home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / aplictns / hp11.3 < prev    next >
Internet Message Format  |  1989-11-13  |  60KB

  1. Path: xanth!lll-winken!brutus.cs.uiuc.edu!wuarchive!texbell!texsun!newstop!sun!swap!page
  2. From: page%swap@Sun.COM (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i200:  hp11 calculator emulator v1.01, Part03/03
  5. Message-ID: <127770@sun.Eng.Sun.COM>
  6. Date: 13 Nov 89 01:36:13 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 2644
  9. Approved: page@sun.com
  10.  
  11. Submitted-by: dg3i+@andrew.cmu.edu (David Gay)
  12. Posting-number: Volume 89, Issue 200
  13. Archive-name: applications/hp11.3
  14.  
  15. # This is a shell archive.
  16. # Remove anything above and including the cut line.
  17. # Then run the rest of the file through 'sh'.
  18. # Unpacked files will be owned by you and have default permissions.
  19. #----cut here-----cut here-----cut here-----cut here----#
  20. #!/bin/sh
  21. # shar: SHell ARchive
  22. # Run the following text through 'sh' to create:
  23. #    ins.c
  24. #    ins.h
  25. #    io.c
  26. #    io.h
  27. #    kbd.c
  28. #    kbd.h
  29. #    lmkdebug
  30. #    lmkfile
  31. #    o/dummy
  32. #    od/dummy
  33. #    prog_codes.c
  34. #    prog_codes.h
  35. #    support.c
  36. #    support.h
  37. # This is archive 3 of a 3-part kit.
  38. # This archive created: Sun Nov 12 17:33:21 1989
  39. echo "extracting ins.c"
  40. sed 's/^X//' << \SHAR_EOF > ins.c
  41. X#include "exec/types.h"
  42. X#include "proto/dos.h"
  43. X
  44. X#include "math.h"
  45. X#include "string.h"
  46. X#include "stdio.h"
  47. X
  48. X#include "hp11/amiga/amiga.h"
  49. X#include "hp11/hp11.h"
  50. X#include "hp11/io.h"
  51. X#include "hp11/support.h"
  52. X#include "hp11/ins.h"
  53. X#include "hp11/codes.h"
  54. X
  55. X#define FOREVER() for(;;)
  56. X
  57. X/* Declare the modules variables */
  58. XBOOL enabled, entering, overflow;
  59. X
  60. XBOOL expo, decpt;
  61. Xchar strx[13], expx[4];
  62. X
  63. X/* Function addresses */
  64. XHP11Function insfunc[KCOMPLEX] =
  65. X{
  66. X   Sqrt,
  67. X   Exp,
  68. X   Exp10,
  69. X   ExpYX,
  70. X   Invert,
  71. X   DoCHS,
  72. X   Divide,
  73. X   SIN,
  74. X   COS,
  75. X   TAN,
  76. X   DoEEX,
  77. X   Times,
  78. X   RunStart,
  79. X   Rdn,
  80. X   ExgXY,
  81. X   ENTER,
  82. X   Minus,
  83. X   DoPoint,
  84. X   SigmaPlus,
  85. X   Plus,
  86. X
  87. X   Pi,
  88. X   XleY,
  89. X   ExgXInd,
  90. X   ToRect,
  91. X   ExgXI,
  92. X   DSE,
  93. X   ISG,
  94. X   XgtY,
  95. X   PSE,
  96. X   ClearSigma,
  97. X   ClearReg,
  98. X   Random,
  99. X   DoPerm,
  100. X   ToHMS,
  101. X   ToRAD,
  102. X   XneY,
  103. X   FRAC,
  104. X   Fact,
  105. X   Estimate,
  106. X   LinearRegression,
  107. X   XeqY,
  108. X
  109. X   Sqr,
  110. X   LN,
  111. X   LOG,
  112. X   Percent,
  113. X   DeltaPercent,
  114. X   ABS,
  115. X   DEG,
  116. X   RAD,
  117. X   GRAD,
  118. X   Xlt0,
  119. X   ArcSIN,
  120. X   ArcCOS,
  121. X   ArcTAN,
  122. X   ToPolar,
  123. X   Xgt0,
  124. X   RTN,
  125. X   Rup,
  126. X   RND,
  127. X   CLX,
  128. X   LSTX,
  129. X   DoComb,
  130. X   ToH,
  131. X   ToDEG,
  132. X   Xne0,
  133. X   INT,
  134. X   Mean,
  135. X   SDev,
  136. X   SigmaSub,
  137. X   Xeq0,
  138. X
  139. X   STORandom,
  140. X   RCLSigma,
  141. X
  142. X   HypSIN,
  143. X   HypCOS,
  144. X   HypTAN,
  145. X
  146. X   ArcHypSIN,
  147. X   ArcHypCOS,
  148. X   ArcHypTAN
  149. X};
  150. X
  151. X/* Various functions used to conserve code space. Could be macros or simply
  152. X  instructions */
  153. Xvoid DISABLE() { enabled = FALSE; entering = FALSE; }
  154. X
  155. Xvoid ENABLE() { enabled = TRUE; entering = FALSE; }
  156. X
  157. Xvoid LisX(void)
  158. X{
  159. X   L = X;
  160. X}
  161. X
  162. Xvoid XisY(void)
  163. X{
  164. X   X = Y;
  165. X}
  166. X
  167. Xvoid YisX(void)
  168. X{
  169. X   Y = X;
  170. X}
  171. X
  172. Xvoid YisZ(void)
  173. X{
  174. X   Y = Z;
  175. X}
  176. X
  177. Xvoid ZisY(void)
  178. X{
  179. X   Z = Y;
  180. X}
  181. X
  182. Xvoid ZisT(void)
  183. X{
  184. X   Z = T;
  185. X}
  186. X
  187. Xvoid TisZ(void)
  188. X{
  189. X   T = Z;
  190. X}
  191. X
  192. X/* Check r against HP11 limits */
  193. Xdouble Check(r)
  194. Xdouble r;
  195. X{
  196. X   if (fabs(r) > MAXHP11) {
  197. X      r = MAXHP11 * sign(r);
  198. X      overflow = TRUE; /* Overflow has occured */
  199. X   }
  200. X   else if (fabs(r) < MINHP11) r = 0.0;
  201. X
  202. X   return(r);
  203. X}
  204. X
  205. Xvoid Drop(void) /* Drop stack & save X in L */
  206. X{
  207. X   ENABLE();
  208. X   LisX(); XisY(); YisZ(); ZisT();
  209. X/* L = X(); X = Y; Y = Z; Z = T; */
  210. X}
  211. X
  212. Xvoid Enter(void) /* Move stack up */
  213. X{
  214. X   TisZ(); ZisY(); YisX();
  215. X/* T = Z; Z = Y; Y = X; */
  216. X}
  217. X
  218. Xvoid Lift(void) /* lift stack if enabled, ENABLE stack */
  219. X{
  220. X   if (enabled) Enter();
  221. X   ENABLE();
  222. X}
  223. X
  224. Xvoid SaveX(void) /* Frequent: L = X; ENABLE(); (most simple instructions eg sin do this) */
  225. X{
  226. X   LisX();
  227. X   ENABLE();
  228. X}
  229. X
  230. X/* Convert x from current trig setting to radians */
  231. Xdouble from(double x)
  232. X{
  233. X   switch (Angles) {
  234. X      case deg:return(FDEG(x));
  235. X      case rad:return(x);
  236. X      case grad:return(FGRAD(x));
  237. X   }
  238. X}
  239. X
  240. X/* Convert radian value to current trig setting */
  241. Xdouble toa(double x)
  242. X{
  243. X   switch (Angles) {
  244. X      case deg:return(TDEG(x));
  245. X      case rad:return(x);
  246. X      case grad:return(TGRAD(x));
  247. X   }
  248. X}
  249. X
  250. X/* Used by statistical formulae (terminology from HP11 doc) */
  251. Xdouble M(void) { return(R[0] * R[2] - R[1] * R[1]); }
  252. X#define N() (R[0] * R[4] - R[3] * R[3]) /* used only once */
  253. Xdouble P(void) { return(R[0] * R[5] - R[1] * R[3]); }
  254. X
  255. Xdouble *Reg(int n) /* Return address of register n */
  256. X{
  257. X   if (n == OI) return(&I);
  258. X   else if (n == OIND_R) /* indirection */
  259. X      if (I >= 0.0 && I < 20.0) return(R + (int)I);
  260. X      else return(NULL); /* Unknown reg */
  261. X   else return(R + n);
  262. X}
  263. X
  264. X/* Convert current input value to real, return false if fails (no exponent) */
  265. Xvoid StdVal(void)
  266. X{
  267. X   X = atof(strx);
  268. X}
  269. X
  270. X/* Convert current input value to real, return false if fails (exponent) */
  271. Xvoid ExpoVal(void)
  272. X{
  273. X   char buf[80];
  274. X
  275. X   /* buf = strx + "E" + expx, with leading blanks stripped from expx */
  276. X   strcat(strcat(strcpy(buf,strx),"E"), stpblk(expx));
  277. X
  278. X   X = atof(buf);
  279. X}
  280. X
  281. X/* Act on key to modify current input value */
  282. Xvoid EnterNum(key)
  283. Xregister int key;
  284. X{
  285. X   register int lens;
  286. X
  287. X   if (!entering) { /* No current digit entry */
  288. X      if (enabled) Enter(); /* lift stack ? */
  289. X      entering = enabled = TRUE; /* stack enabled, number being entered */
  290. X      expo = decpt = FALSE; /* No dec point or exponent */
  291. X      strx[0] = ' '; strx[1] = '\0'; /* nb string empty (leading space for sign) */
  292. X   }
  293. X
  294. X   lens = strlen(strx); /* Current string length */
  295. X   if (key >= KFIG + 0 && key <= KFIG + 9) /* Add digit */
  296. X      if (expo) { /* to exponent */
  297. X     expx[1] = expx[2]; expx[2] = key - KFIG + '0';
  298. X      }
  299. X      else {
  300. X     strx[lens] = key - KFIG + '0'; strx[lens + 1] = '\0';
  301. X     strx[scrpos(strx, 11) + 1] = '\0'; /* Cut string at end of hp11 screen pos
  302. X        ==> prevent display overflow */
  303. X      }
  304. X   else
  305. X      switch (key) {
  306. X     case -IBACK: /* back-arrow, actions are passed as negative numbers to
  307. X        distinguish them from instructions */
  308. X        if (expo) /* Correct exponent */
  309. X           if (strcmp(expx, "-00") == 0) strcpy(expx, " 00");
  310. X           else if (strcmp(expx, " 00") == 0) expo = FALSE; /* delete exponent */
  311. X           else {
  312. X          expx[2] = expx[1]; expx[1] = '0';
  313. X           }
  314. X        else /* no exponent */
  315. X           if (lens == 2) { CLX(); return; } /* end of digit entry,
  316. X          must not evaluate current entry ==> exit */
  317. X           else {
  318. X          if (strx[lens - 1] == '.') decpt = FALSE;
  319. X          strx[lens - 1] = '\0'; /* cut last char from str by moving eos mark */
  320. X           }
  321. X        break;
  322. X     case KCHS:
  323. X        if (expo) { /* change exponent sign */
  324. X           expx[0] = (expx[0] == '-') ? ' ' : '-';
  325. X        }
  326. X        else { /* change number sign */
  327. X           strx[0] = (strx[0] == '-') ? ' ' : '-';
  328. X        }
  329. X        break;
  330. X     case KPOINT:
  331. X        if (!expo && !decpt) {
  332. X           decpt = TRUE;
  333. X
  334. X           if (lens == 1) { strcpy(strx, " 0"); lens = 2; } /* if no digit entered, add a 0 */
  335. X           strx[lens] = '.'; strx[lens + 1] = '\0';
  336. X           strx[scrpos(strx, 11) + 1] = '\0';
  337. X        }
  338. X        break;
  339. X     case KEEX:
  340. X        if (!expo) {
  341. X           expo = TRUE;
  342. X           strcpy(expx, " 00");
  343. X           if (lens == 1) strcpy(strx, " 1"); /* if no digit entered, add a 1 */
  344. X        }
  345. X      }
  346. X   if (expo) ExpoVal();
  347. X   else StdVal();
  348. X}
  349. X
  350. Xvoid ExpYX() /* y^x */
  351. X{
  352. X   double t;
  353. X
  354. X   errno = 0; /* set return code to 0 */
  355. X   t = pow(Y, X);
  356. X   if (errno != 0) Error('0'); /* Check math library return code */
  357. X   else {
  358. X      Y = t;
  359. X      Drop();
  360. X   }
  361. X}
  362. X
  363. Xvoid CHS(void)
  364. X{
  365. X   ENABLE();
  366. X   X = -X;
  367. X}
  368. X
  369. Xvoid DoCHS()
  370. X{
  371. X   if (entering) EnterNum(KCHS);
  372. X   else CHS();
  373. X}
  374. X
  375. Xvoid DoEEX()
  376. X{
  377. X   EnterNum(KEEX);
  378. X}
  379. X
  380. Xvoid DoPoint()
  381. X{
  382. X   EnterNum(KPOINT);
  383. X}
  384. X
  385. Xvoid Rdn()
  386. X{
  387. X   double t;
  388. X
  389. X   ENABLE();
  390. X   t = X; XisY(); YisZ(); ZisT(); T = t;
  391. X/* t = X; X = Y; Y = Z; Z = T; T = t; */
  392. X}
  393. X
  394. Xvoid ExgXY() /* Exchange X & Y */
  395. X{
  396. X   double t;
  397. X
  398. X   ENABLE();
  399. X   t = X; XisY(); Y = t;
  400. X/* t = X; X = Y; Y = t; */
  401. X}
  402. X
  403. Xvoid ClearReg()
  404. X{
  405. X   int i;
  406. X
  407. X   NEUTRAL();
  408. X   for (i = 0; i < 20; i++) R[i] = 0.0;
  409. X   I = 0;
  410. X}
  411. X
  412. Xvoid Estimate() /* Statistics: estimate y from given x */
  413. X{
  414. X   double tm = M(), tr, ty, tp = P(); /* temporary results */
  415. X
  416. X   tr = tm * N();
  417. X   ty = R[0] * tm;
  418. X
  419. X   if (tr < 0.0 || ty == 0.0) Error('2'); /* Stat error */
  420. X   else {
  421. X      Enter(); /* always lifts stack */
  422. X      SaveX();
  423. X
  424. X      X = (tm * R[3] + tp * (R[0] * X - R[1])) / ty; /* estimate */
  425. X      Y = tp / sqrt(tr); /* Correlation coefficient */
  426. X   }
  427. X}
  428. X
  429. Xvoid LinearRegression()
  430. X{
  431. X   double tm = M(), tp = P();
  432. X
  433. X   if (tm == 0.0 || R[0] == 0.0) Error('2');
  434. X   else {
  435. X      Lift(); /* Lift stack twice */
  436. X      Enter();
  437. X
  438. X      Y = tp / tm;
  439. X      X = (tm * R[3] - tp * R[1]) / (R[0] * tm);
  440. X   }
  441. X}
  442. X
  443. Xvoid Rup()
  444. X{
  445. X   double t;
  446. X
  447. X   ENABLE();
  448. X   t = T; TisZ(); ZisY(); YisX(); X = t;
  449. X/* t = T; T = Z; Z = Y; Y = X; X = t; */
  450. X}
  451. X
  452. Xvoid SDev()
  453. X{
  454. X   double tx, ty, td;
  455. X
  456. X   td = R[0] * (R[0] - 1.0);
  457. X
  458. X   if (td == 0.0) Error('2');
  459. X   else {
  460. X      tx = M() / td;
  461. X      ty = N() / td;
  462. X
  463. X      if (tx < 0.0 || ty < 0.0) Error('2');
  464. X      else {
  465. X     Lift();
  466. X     Enter();
  467. X
  468. X     X = sqrt(tx); Y = sqrt(ty);
  469. X      }
  470. X   }
  471. X}
  472. X
  473. Xvoid FIX(n)
  474. Xint n;
  475. X{
  476. X   NEUTRAL();
  477. X   Mode = fix; Digits = n;
  478. X   minfix = pow(10.0, (double)-Digits);
  479. X}
  480. X
  481. Xvoid SCI(n)
  482. Xint n;
  483. X{
  484. X   NEUTRAL();
  485. X   Mode = sci; Digits = n;
  486. X}
  487. X
  488. Xvoid ENG(n)
  489. Xint n;
  490. X{
  491. X   NEUTRAL();
  492. X   Mode = eng; Digits = n;
  493. X}
  494. X
  495. Xvoid ExgXI() /* Exchange X with I */
  496. X{
  497. X   double t;
  498. X
  499. X   ENABLE();
  500. X   t = I; I = X; X = t;
  501. X}
  502. X
  503. Xvoid ExgXInd() /* Exchange X with (i) */
  504. X{
  505. X   double t, *ptr;
  506. X
  507. X   if (!(ptr = Reg(OIND_R))) Error('3'); /* get address of pointed register if exists */
  508. X   else {
  509. X      ENABLE();
  510. X      t = *ptr; *ptr = X; X = t;
  511. X   }
  512. X}
  513. X
  514. Xvoid STO(n, type)
  515. Xint n;
  516. Xenum StoTypes type;
  517. X{
  518. X   double val;
  519. X   register double *ptr;
  520. X
  521. X   if (ptr = Reg(n)) { /* Valid register */
  522. X
  523. X      switch (type) {
  524. X     case sto: val = X; break;
  525. X     case add: val = *ptr + X; break;
  526. X     case sub: val = *ptr - X; break;
  527. X     case mul: val = *ptr * X; break;
  528. X     case div: if (X == 0.0) {
  529. X              Error('0');
  530. X              return; /* exit if error */
  531. X           }
  532. X           else val = *ptr / X; break;
  533. X      }
  534. X
  535. X      if (fabs(val) > MAXHP11) Error('1'); /* Register overflow */
  536. X      else {
  537. X     *ptr = val;
  538. X     ENABLE();
  539. X      }
  540. X   }
  541. X   else Error('3');
  542. X}
  543. X
  544. Xvoid RCL(n)
  545. Xint n;
  546. X{
  547. X   double *ptr;
  548. X
  549. X   if (ptr = Reg(n)) {
  550. X      Lift();
  551. X      X = *ptr;
  552. X   }
  553. X   else Error('3');
  554. X}
  555. X
  556. Xvoid GTOLine(n) /* move to line n */
  557. Xint n;
  558. X{
  559. X   if (n >= 0 && n <= lastIns) PC = n;
  560. X   else Error('4');
  561. X}
  562. X
  563. Xvoid ProgramEntry() /* Enter a program */
  564. X{
  565. X   register int i;
  566. X   WORD code;
  567. X   register int inprog = TRUE;
  568. X
  569. X   RelKey();
  570. X
  571. X   ENABLE();
  572. X
  573. X   do {
  574. X      DisplayLine(); DispPRGM(TRUE); /* Program display */
  575. X
  576. X      switch (ReadKey(&code)) {
  577. X     case Instruction: /* Save it */
  578. X        if (lastIns == MAXPROG) Error('4'); /* Memory full */
  579. X        else {
  580. X           for (i = lastIns; i > PC; i--) Prog[i + 1] = Prog[i]; /* Move program up */
  581. X           lastIns++;
  582. X           Prog[++PC] = code; /* store instruction */
  583. X           retCnt = 0; /* Empty return stack */
  584. X        };
  585. X        break;
  586. X     case Action: /* Act on it */
  587. X        if (code >= IGTO_LINE) GTOLine(code - IGTO_LINE);
  588. X        else switch (code) {
  589. X           case ION: on = inprog = !RelKey(); break; /* Allow user to change his mind */
  590. X           case IP_R: case IRESET: inprog = FALSE; break; /* exit program mode */
  591. X           case IMEM: MEM(); break;
  592. X           case IBACK: /* delete line */
  593. X          if (PC != 0) {
  594. X             for (i = PC; i < lastIns; i++) Prog[i] = Prog[i + 1]; /* del line */
  595. X             lastIns--;
  596. X             PC--;
  597. X             retCnt = 0; /* empty stack when prog changed */
  598. X          }
  599. X          break;
  600. X           case ISST: if (PC++ == lastIns) PC = 0; break;
  601. X           case IBST: if (PC-- == 0) PC = lastIns; break;
  602. X           case IUSER: USER(); break;
  603. X           case ICLR_PRGM: lastIns = PC = 0; break;
  604. X        }
  605. X        break;
  606. X      }
  607. X      RelKey();
  608. X   } while (inprog);
  609. X}
  610. X
  611. Xvoid GTOLBL(int n)
  612. X{
  613. X   register int i;
  614. X
  615. X   if (n > 14) Error('4');
  616. X   else { /* Do a circular search from current line */
  617. X      for (i = PC + 1; i <= lastIns; i++) /* Search from current line */
  618. X     if (Prog[i] == KLBL + n) {
  619. X        PC = i; return; /* found, exit */
  620. X     }
  621. X      for (i = 1; i < PC; i++) /* If that fails, search from start */
  622. X     if (Prog[i] == KLBL + n) {
  623. X        PC = i; return;
  624. X     }
  625. X      Error('4');
  626. X   }
  627. X}
  628. X
  629. Xvoid GTO(n)
  630. Xint n;
  631. X{
  632. X   if (n == OIND_G) /* Indirection */
  633. X      if (I >= 0.0) GTOLBL((int)I); /* gto label if I >= 0 */
  634. X      else GTOLine(-(int)I); /* gto line -I if i < 0 */
  635. X   else GTOLBL(n);
  636. X   if (!error) { /* success */
  637. X      ENABLE();
  638. X      if (running) PC--; /* Execute label instruction (even though useless),
  639. X     must decrement PC in run mode because incremented after end ins */
  640. X      else retCnt = 0; /* in normal mode, GTO clears return stack */
  641. X   }
  642. X}
  643. X
  644. Xvoid BreakupI(int *limit, int *step) /* From I deduce loop limit & step.
  645. X I is stored as nnnnn.lllss with nnnnn as the loop count, lll the limit &
  646. X ss the step. If ss == 0, the step is taken as 1 */
  647. X{
  648. X   double t;
  649. X
  650. X   t = frac(I) * 1000.0;
  651. X   *limit = (int)t;
  652. X   *step = (int)(100.0 * (t - *limit));
  653. X   if (*step == 0) *step = 1;
  654. X}
  655. X
  656. Xvoid DSE()
  657. X{
  658. X   int limit, step;
  659. X
  660. X   ENABLE();
  661. X   BreakupI(&limit, &step);
  662. X   I -= step;
  663. X
  664. X   skip = (I <= limit);
  665. X}
  666. X
  667. Xvoid ISG()
  668. X{
  669. X   int limit, step;
  670. X
  671. X   ENABLE();
  672. X   BreakupI(&limit, &step);
  673. X   I += step;
  674. X
  675. X   skip = (I > limit);
  676. X}
  677. X
  678. Xvoid SF(n)
  679. Xint n;
  680. X{
  681. X   ENABLE();
  682. X   Flags |= (1 << n);
  683. X}
  684. X
  685. Xvoid CF(n)
  686. Xint n;
  687. X{
  688. X   ENABLE();
  689. X   Flags &= ~(1 << n);
  690. X}
  691. X
  692. Xvoid Set(n) /* Is flag n set ? */
  693. Xint n;
  694. X{
  695. X   ENABLE();
  696. X   skip = !(Flags & (1 << n));
  697. X}
  698. X
  699. Xvoid PSE()
  700. X{
  701. X   BOOL oldrun = running;
  702. X
  703. X   NEUTRAL();
  704. X   running = FALSE;
  705. X   Disp();
  706. X   Wait50(50);
  707. X   running = oldrun;
  708. X}
  709. X
  710. Xvoid RTN()
  711. X{
  712. X   ENABLE();
  713. X   if (!running || retCnt == 0) { /* In normal mode RTN sets PC to 0 &
  714. X      clears the return stack. In run mode, if the stack is empty, it also
  715. X      sets PC to 0 & then it interrupts the program */
  716. X      running = FALSE;
  717. X      PC = 0; retCnt = 0;
  718. X   }
  719. X   else /* Return from subroutine */
  720. X      PC = retStack[--retCnt];
  721. X}
  722. X
  723. Xvoid GSB(n)
  724. Xint n;
  725. X{
  726. X   if (retCnt == MAXSTACK) Error('5'); /* Stack full */
  727. X   else {
  728. X      if (running) {
  729. X     retStack[retCnt++] = PC; /* Save PC */
  730. X     GTO(n); /* Jump to prog line */
  731. X     if (error) retCnt--; /* If this fails, reclaim stack space */
  732. X      }
  733. X      else { /* in normal mode, GSB = GTO + R/S */
  734. X     retCnt = 0;
  735. X     GTO(n);
  736. X     running = !error;
  737. X      }
  738. X   }
  739. X}
  740. X
  741. Xvoid HP11ColdReset() /* ColdReset HP11 (Menu option: New) */
  742. X{
  743. X   Display("  Pr Error");
  744. X
  745. X   DEG();
  746. X   FIX(4);
  747. X   PC = lastIns = 0;
  748. X   running = User = comma = FALSE;
  749. X   Flags = retCnt = 0;
  750. X   ClearSigma(); L = 0.0;
  751. X   ClearReg();
  752. X
  753. X   GetKey();
  754. X}
  755. X
  756. Xvoid MEM() /* Display available memory */
  757. X{
  758. X   char mem[20];
  759. X
  760. X   NEUTRAL();
  761. X   sprintf(mem, " P-%-4dr- .9", MAXPROG - lastIns);
  762. X   /* There are always all the register hence the r- .9, %-4d left justifies the number
  763. X     of lines in a 4 character field */
  764. X   Display(mem);
  765. X   RelKey();
  766. X}
  767. X
  768. Xvoid PREFIX() /* Display digits of number in x */
  769. X{
  770. X   char *disp, buf[20];
  771. X   int dec, sign;
  772. X
  773. X   NEUTRAL();
  774. X
  775. X   if (X != 0.0) {
  776. X      disp = ecvt(X, 10, &dec, &sign); /* The ideal library function for this */
  777. X      buf[0] = ' '; strcpy(buf + 1, disp);
  778. X      Display(buf);
  779. X   }
  780. X   else Display(" 0000000000");
  781. X
  782. X   RelKey();
  783. X}
  784. X
  785. Xvoid RND()
  786. X{
  787. X   double fx, tx;
  788. X   char buf[20];
  789. X
  790. X   SaveX();
  791. X
  792. X   switch (Mode) {
  793. X      case fix:
  794. X     fx = modf(X, &tx);
  795. X     X = tx + trunc(fx / minfix + 0.5) * minfix;
  796. X     break;
  797. X      case sci: case eng:
  798. X     sprintf(buf, "%0.*e", Digits, X);
  799. X     X = atof(buf);
  800. X     break;
  801. X   }
  802. X}
  803. X
  804. Xvoid Sqrt()
  805. X{
  806. X   if (X < 0.0) Error('0');
  807. X   else {
  808. X      SaveX(); X = sqrt(X);
  809. X   }
  810. X}
  811. X
  812. Xvoid Exp() /* e^x */
  813. X{
  814. X   SaveX(); X = exp(X);
  815. X}
  816. X
  817. Xvoid Exp10() /* 10^x */
  818. X{
  819. X   SaveX(); X = pow(10.0, X);
  820. X}
  821. X
  822. Xvoid Invert() /* 1/x */
  823. X{
  824. X   if (X == 0.0) Error('0');
  825. X   else {
  826. X      SaveX(); X = 1.0 / X;
  827. X   }
  828. X}
  829. X
  830. Xvoid Divide()
  831. X{
  832. X   if (X == 0.0) Error('0');
  833. X   else {
  834. X      Y = Y / X;
  835. X      Drop();
  836. X   }
  837. X}
  838. X
  839. Xvoid SIN()
  840. X{
  841. X   SaveX(); X = sin(from(X));
  842. X}
  843. X
  844. Xvoid COS()
  845. X{
  846. X   SaveX(); X = cos(from(X));
  847. X}
  848. X
  849. Xvoid TAN()
  850. X{
  851. X   SaveX(); X = tan(from(X));
  852. X}
  853. X
  854. Xvoid Times()
  855. X{
  856. X   Y = Y * X;
  857. X   Drop();
  858. X}
  859. X
  860. Xvoid ENTER()
  861. X{
  862. X   DISABLE();
  863. X   Enter();
  864. X}
  865. X
  866. Xvoid Minus()
  867. X{
  868. X   Y = Y - X;
  869. X   Drop();
  870. X}
  871. X
  872. Xvoid SigmaPlus() /* Accumulate statistics */
  873. X{
  874. X   R[0] += 1.0;
  875. X   R[1] = Check(R[1] + X);
  876. X   R[2] = Check(R[2] + X * X);
  877. X   R[3] = Check(R[3] + Y);
  878. X   R[4] = Check(R[4] + Y * Y);
  879. X   R[5] = Check(R[5] + X * Y);
  880. X
  881. X   DISABLE();
  882. X   LisX(); X = R[0];
  883. X}
  884. X
  885. Xvoid Plus()
  886. X{
  887. X   Y = Y + X;
  888. X   Drop();
  889. X}
  890. X
  891. Xvoid Pi()
  892. X{
  893. X   Lift();
  894. X   X = PI;
  895. X}
  896. X
  897. X
  898. Xvoid ToRect()
  899. X{
  900. X   SaveX();
  901. X   Rect(X, from(Y), &X, &Y);
  902. X}
  903. X
  904. Xvoid ClearSigma() /* Clear statistics */
  905. X{
  906. X   NEUTRAL(); /* Doesn't really matter, could be anything (but the HP11 doc says
  907. X      neutral so it will be neutral ... */
  908. X   X = Y = Z = T = R[0] = R[1] = R[2] = R[3] = R[4] = R[5] = 0.0;
  909. X}
  910. X
  911. Xvoid Random() /* Random number generator. This isn't the same as the HP11 one, for I
  912. X   don't know what the HP11 uses. */
  913. X{
  914. X   Lift();
  915. X   X = drand48();
  916. X}
  917. X
  918. Xvoid DoPerm() /* P y,x */
  919. X{
  920. X   if (X <= Y && X > 0.0) {
  921. X      Y = Perm((int)Y, (int)X);
  922. X      Drop();
  923. X   }
  924. X   else Error('0');
  925. X}
  926. X
  927. Xvoid ToHMS()
  928. X{
  929. X   SaveX(); X = hms(X);
  930. X}
  931. X
  932. Xvoid ToRAD()
  933. X{
  934. X   SaveX(); X = FDEG(X);
  935. X}
  936. X
  937. Xvoid FRAC()
  938. X{
  939. X   SaveX(); X = frac(X);
  940. X}
  941. X
  942. Xvoid Fact() /* gamma/factorial function */
  943. X{
  944. X   SaveX();
  945. X   if (X > MAXFACT) X = MAXHP11;
  946. X   else if (X >= 0 && X == trunc(X)) X = factorial((int)X);
  947. X   else X = gamma(1.0 + X);
  948. X}
  949. X
  950. Xvoid Sqr()
  951. X{
  952. X   SaveX(); X = X * X;
  953. X}
  954. X
  955. Xvoid LN()
  956. X{
  957. X   if (X <= 0.0) Error('0');
  958. X   else {
  959. X      SaveX(); X = log(X);
  960. X   }
  961. X}
  962. X
  963. Xvoid LOG()
  964. X{
  965. X   if (X <= 0.0) Error('0');
  966. X   else {
  967. X      SaveX(); X = log10(X);
  968. X   }
  969. X}
  970. X
  971. Xvoid Percent()
  972. X{
  973. X   /* doesn't drop stack */
  974. X   SaveX(); X = X * Y / 100.0;
  975. X}
  976. X
  977. Xvoid DeltaPercent() /* Percentage of difference between x & y */
  978. X{
  979. X   if (Y == 0.0) Error('0');
  980. X   else {
  981. X      SaveX(); X = 100.0 * (X - Y) / Y;
  982. X   }
  983. X}
  984. X
  985. Xvoid ABS()
  986. X{
  987. X   SaveX(); X = fabs(X);
  988. X}
  989. X
  990. X
  991. Xvoid DEG()
  992. X{
  993. X   NEUTRAL();
  994. X   Angles = deg;
  995. X}
  996. X
  997. Xvoid RAD()
  998. X{
  999. X   NEUTRAL();
  1000. X   Angles = rad;
  1001. X}
  1002. X
  1003. Xvoid GRAD()
  1004. X{
  1005. X   NEUTRAL();
  1006. X   Angles = grad;
  1007. X}
  1008. X
  1009. Xvoid ArcSIN()
  1010. X{
  1011. X   if (fabs(X) > 1.0) Error('0');
  1012. X   else {
  1013. X      SaveX(); X = toa(asin(X));
  1014. X   }
  1015. X}
  1016. X
  1017. Xvoid ArcCOS()
  1018. X{
  1019. X   if (fabs(X) > 1.0) Error('0');
  1020. X   else {
  1021. X      SaveX(); X = toa(acos(X));
  1022. X   }
  1023. X}
  1024. X
  1025. Xvoid ArcTAN()
  1026. X{
  1027. X   SaveX(); X = toa(atan(X));
  1028. X}
  1029. X
  1030. Xvoid ToPolar()
  1031. X{
  1032. X   SaveX();
  1033. X   Polar(X, Y, &X, &Y);
  1034. X   Y = toa(Y);
  1035. X}
  1036. X
  1037. Xvoid CLX()
  1038. X{
  1039. X   X = 0.0;
  1040. X   DISABLE();
  1041. X}
  1042. X
  1043. Xvoid LSTX()
  1044. X{
  1045. X   Lift();
  1046. X   X = L;
  1047. X}
  1048. X
  1049. Xvoid DoComb() /* C y,x */
  1050. X{
  1051. X   if (X <= Y && X > 0.0) {
  1052. X      Y = Comb((int)Y, (int)X);
  1053. X      Drop();
  1054. X   }
  1055. X   else Error('0');
  1056. X}
  1057. X
  1058. Xvoid ToH()
  1059. X{
  1060. X   SaveX(); X = hr(X);
  1061. X}
  1062. X
  1063. Xvoid ToDEG()
  1064. X{
  1065. X   SaveX(); X = TDEG(X);
  1066. X}
  1067. X
  1068. Xvoid INT()
  1069. X{
  1070. X   SaveX(); X = trunc(X);
  1071. X}
  1072. X
  1073. Xvoid Mean()
  1074. X{
  1075. X   if (R[0] == 0.0) Error('2');
  1076. X   else {
  1077. X      Lift();
  1078. X      Enter();
  1079. X
  1080. X      X = R[1] / R[0];
  1081. X      Y = R[3] / R[0];
  1082. X   }
  1083. X}
  1084. X
  1085. Xvoid SigmaSub() /* Correct error in statistics accumulation */
  1086. X{
  1087. X   R[0] -= 1.0;
  1088. X   R[1] = Check(R[1] - X);
  1089. X   R[2] = Check(R[2] - X * X);
  1090. X   R[3] = Check(R[3] - Y);
  1091. X   R[4] = Check(R[4] - Y * Y);
  1092. X   R[5] = Check(R[5] - X * Y);
  1093. X
  1094. X   DISABLE();
  1095. X   LisX(); X = R[0];
  1096. X}
  1097. X
  1098. Xvoid HypSIN()
  1099. X{
  1100. X   SaveX(); X = sinh(X);
  1101. X}
  1102. X
  1103. Xvoid HypCOS()
  1104. X{
  1105. X   SaveX(); X = cosh(X);
  1106. X}
  1107. X
  1108. Xvoid HypTAN()
  1109. X{
  1110. X   SaveX(); X = tanh(X);
  1111. X}
  1112. X
  1113. Xvoid ArcHypSIN()
  1114. X{
  1115. X   SaveX(); X = asinh(X);
  1116. X}
  1117. X
  1118. Xvoid ArcHypCOS()
  1119. X{
  1120. X   if (fabs(X) < 1.0) Error('0');
  1121. X   else {
  1122. X      SaveX(); X = acosh(X);
  1123. X   }
  1124. X}
  1125. X
  1126. Xvoid ArcHypTAN()
  1127. X{
  1128. X   if (fabs(X) > 1.0) Error('0');
  1129. X   else {
  1130. X      SaveX(); X = atanh(X);
  1131. X   }
  1132. X}
  1133. X
  1134. Xvoid STORandom() /* Set random generator seed */
  1135. X{
  1136. X   ENABLE();
  1137. X   srand48((long)X);
  1138. X   /* Use integer part of seed, something better could be used */
  1139. X}
  1140. X
  1141. Xvoid RCLSigma() /* Recall accumulated x & y totals */
  1142. X{
  1143. X   Lift();
  1144. X   Enter();
  1145. X
  1146. X   X = R[1]; Y = R[3];
  1147. X}
  1148. X
  1149. Xvoid USER() /* Toggle user mode */
  1150. X{
  1151. X   NEUTRAL();
  1152. X   User = !User;
  1153. X}
  1154. X
  1155. Xvoid RunStart() /* Should be called RunStop ! */
  1156. X{
  1157. X   NEUTRAL();
  1158. X   if (running) running = FALSE; /* Stop */
  1159. X   else { /* Run */
  1160. X      if (lastIns != 0) { /* if a program to run */
  1161. X     running = TRUE;
  1162. X     if (PC == 0) PC = 1; /* skip first line */
  1163. X      }
  1164. X
  1165. X      DisplayLine(); /* Display first line */
  1166. X      RelKey();
  1167. X   }
  1168. X}
  1169. X
  1170. Xvoid XleY()
  1171. X{
  1172. X   ENABLE();
  1173. X   skip = (X > Y); /* skip if condition fails */
  1174. X}
  1175. X
  1176. Xvoid Xlt0()
  1177. X{
  1178. X   ENABLE();
  1179. X   skip = (X >= 0.0);
  1180. X}
  1181. X
  1182. Xvoid XgtY()
  1183. X{
  1184. X   ENABLE();
  1185. X   skip = (X <= Y);
  1186. X}
  1187. X
  1188. Xvoid Xgt0()
  1189. X{
  1190. X   ENABLE();
  1191. X   skip = (X <= 0.0);
  1192. X}
  1193. X
  1194. Xvoid XneY()
  1195. X{
  1196. X   ENABLE();
  1197. X   skip = (X == Y);
  1198. X}
  1199. X
  1200. Xvoid Xne0()
  1201. X{
  1202. X   ENABLE();
  1203. X   skip = (X == 0.0);
  1204. X}
  1205. X
  1206. Xvoid XeqY()
  1207. X{
  1208. X   ENABLE();
  1209. X   skip = (X != Y);
  1210. X}
  1211. X
  1212. Xvoid Xeq0()
  1213. X{
  1214. X   ENABLE();
  1215. X   skip = (X != 0.0);
  1216. X}
  1217. X
  1218. Xvoid SST() /* Single step a program */
  1219. X{
  1220. X   if (lastIns == 0) { /* No program to single step through */
  1221. X      DisplayLine();
  1222. X      RelKey();
  1223. X   }
  1224. X   else {
  1225. X      if (PC == 0) PC = 1; /* skip line 0 */
  1226. X
  1227. X      DisplayLine();
  1228. X      RelKey();
  1229. X
  1230. X      running = TRUE; /* Pretend line is being run */
  1231. X      ExecIns(Prog[PC]); /* Exec ins */
  1232. X      if (!error && !overflow) { /* idem main loop */
  1233. X     if (skip) PC++;
  1234. X     PC++;
  1235. X     while (PC > lastIns) {
  1236. X        RTN();
  1237. X        PC++;
  1238. X     }
  1239. X      }
  1240. X      running = FALSE;
  1241. X
  1242. X   }
  1243. X}
  1244. X
  1245. Xvoid BST() /* move back one line (but don't correct its effect) */
  1246. X{
  1247. X   if (PC == 0) PC = lastIns;
  1248. X   else PC--;
  1249. X
  1250. X   DisplayLine();
  1251. X   RelKey();
  1252. X}
  1253. X
  1254. X
  1255. SHAR_EOF
  1256. echo "extracting ins.h"
  1257. sed 's/^X//' << \SHAR_EOF > ins.h
  1258. X/* HP11 numeric limits */
  1259. X#define MAXHP11 9.999999999E99
  1260. X#define MINHP11 1E-99
  1261. X#define MAXFACT 69.95757445
  1262. X
  1263. X/* The different type of sto operations. The order must reflect the ordering of
  1264. X  instruction codes in code.h */
  1265. Xenum StoTypes {sto, add, sub, mul, div};
  1266. X
  1267. Xextern BOOL enabled, entering, overflow; /* Various flags related to the instructions */
  1268. X
  1269. X/* Current entry value, used during number entry */
  1270. Xextern BOOL expo, decpt; /* expo true for an exponent present, decpt true for decimal point */
  1271. Xextern char strx[13], expx[4];
  1272. X
  1273. Xtypedef void (*HP11Function)(void);
  1274. X
  1275. Xextern HP11Function insfunc[];
  1276. X
  1277. X/* Function declarations */
  1278. X/* ===================== */
  1279. Xdouble Check(double); /* Check the argument for HP11 limits (1e-99 --> 1e100),
  1280. X   return adjusted value if out of limits */
  1281. Xvoid DISABLE(void); /* Disable stack */
  1282. Xvoid ENABLE(void); /* Enable stack */
  1283. Xvoid Enter(void); /* Do an "Enter" */
  1284. X#define NEUTRAL() { entering = FALSE; } /* Neutral operation, simply end
  1285. X number entry */
  1286. X
  1287. X/* Instructions */
  1288. Xvoid FIX(int); /* set display mode to FIX n */
  1289. Xvoid SCI(int);
  1290. Xvoid ENG(int);
  1291. Xvoid STO(int, enum StoTypes); /* Sto in reg n (0 <= n <= 21, with 20 = I, 21 = (i)),
  1292. X with desired operation */
  1293. Xvoid RCL(int); /* RCl, n same as for sto */
  1294. Xvoid EnterNum(int); /* Add keycode to current number */
  1295. Xvoid GTO(int); /* Goto label n (n = 0 to 9, A to E (10 to 14) or I (15) : indirection */
  1296. Xvoid SF(int), CF(int), Set(int);
  1297. Xvoid GSB(int); /* Call subprogram n (cf GTO) */
  1298. Xvoid GTOLine(int); /* Jump to line in prog */
  1299. X
  1300. X#ifdef ABS
  1301. X#undef ABS
  1302. X#endif
  1303. X
  1304. Xvoid Sqrt(void), Exp(void), Exp10(void), ExpYX(void), Invert(void),
  1305. X     Divide(void), SIN(void), COS(void), TAN(void), Times(void), Rdn(void),
  1306. X     ExgXY(void), ENTER(void), Minus(void), SigmaPlus(void), Plus(void),
  1307. X     Pi(void), ToRect(void), ClearSigma(void), ClearReg(void), Random(void),
  1308. X     DoPerm(void), ToHMS(void), ToRAD(void), FRAC(void), Fact(void),
  1309. X     Estimate(void), LinearRegression(void), Sqr(void), LN(void), LOG(void),
  1310. X     Percent(void), DeltaPercent(void), ABS(void), DEG(void), RAD(void),
  1311. X     GRAD(void), ArcSIN(void), ArcCOS(void), ArcTAN(void), ToPolar(void),
  1312. X     Rup(void), CLX(void), LSTX(void), DoComb(void), ToH(void), ToDEG(void),
  1313. X     INT(void), Mean(void), SDev(void), SigmaSub(void), HypSIN(void),
  1314. X     HypCOS(void), HypTAN(void), ArcHypSIN(void), ArcHypCOS(void),
  1315. X     ArcHypTAN(void), ExgXI(void), STORandom(void), RCLSigma(void), USER(void),
  1316. X     ProgarmEntry(void), RunStart(void), XleY(void), Xlt0(void),
  1317. X     DSE(void), ISG(void), XgtY(void), Xgt0(void), PSE(void), XneY(void),
  1318. X     Xne0(void), XeqY(void), Xeq0(void), RTN(void), SST(void), BST(void),
  1319. X     HP11ColdReset(void), MEM(void), PREFIX(void), RND(void), DoCHS(void),
  1320. X     DoPoint(void), DoEEX(void), ExgXInd(void), ProgramEntry(void);
  1321. X
  1322. SHAR_EOF
  1323. echo "extracting io.c"
  1324. sed 's/^X//' << \SHAR_EOF > io.c
  1325. X#include "exec/types.h"
  1326. X
  1327. X#include "stdlib.h"
  1328. X#include "stdio.h"
  1329. X#include <math.h>
  1330. X#include "string.h"
  1331. X
  1332. X#include "hp11/hp11.h"
  1333. X#include "hp11/amiga/amiga.h"
  1334. X#include "hp11/ins.h"
  1335. X#include "hp11/io.h"
  1336. X#include "hp11/kbd.h"
  1337. X#include "hp11/codes.h"
  1338. X#include "hp11/prog_codes.h"
  1339. X
  1340. X#define MAXRUN 4 /* Length of time running is displayed */
  1341. X
  1342. X#define FOREVER for (;;)
  1343. X
  1344. Xint comma;
  1345. X
  1346. Xstatic char *stpich(char *p, int c) /* insert character c at front of string p */
  1347. X{
  1348. X   movmem(p, p + 1, strlen(p) + 1);
  1349. X   *p = c;
  1350. X
  1351. X   return(p);
  1352. X}
  1353. X
  1354. Xint GetKey() /* Read a key & wait for its release */
  1355. X{
  1356. X   int key;
  1357. X
  1358. X   key = PollKey(TRUE);
  1359. X   RelKey();
  1360. X
  1361. X   return(key);
  1362. X}
  1363. X
  1364. Xenum KeyTypes ReadKey(code) /* Read a complete key sequence, & return
  1365. X its type, intrsuction or action. */
  1366. Xregister WORD *code;
  1367. X{
  1368. X   register struct Key *curtkey;
  1369. X   register int key, offset;
  1370. X   register BOOL noKey; /* if an invalid sequence is returned, don't read a new key,
  1371. X      reuse the one which caused the error. This is set to false when that happens */
  1372. X   register enum KeyTypes ret;
  1373. X
  1374. X   noKey = TRUE; /* no key read */
  1375. X
  1376. X   FOREVER {
  1377. X      offset = 0; /* f or g not pressed */
  1378. X
  1379. X      FOREVER { /* This loop reads a key from the main, f or g shifted keyboards.
  1380. X     Further refinements (eg sto) are done algorithmically, to save space */
  1381. X     if (noKey) key = PollKey(TRUE); /* obtain next key */
  1382. X     Dispf(FALSE); Dispg(FALSE);
  1383. X     noKey = TRUE;
  1384. X     if (key == 31) { /* f pressed, toggle its status */
  1385. X        offset = (offset == NUMKEYS) ? 0 : (Dispf(TRUE), NUMKEYS);
  1386. X        RelKey();
  1387. X     }
  1388. X     else if (key == 32) { /* g */
  1389. X        offset = (offset == NUMKEYS + NUMKEYS) ? 0 : (Dispg(TRUE), NUMKEYS + NUMKEYS);
  1390. X        RelKey();
  1391. X     }
  1392. X     else break;/* got a key, exit from loop */
  1393. X      }
  1394. X      if (User && key < 5) offset ^= NUMKEYS; /* Toggle f for first five keys. This
  1395. X       doesn't affect g because the bit patterns are exclusive (42 & 84 = 0) */
  1396. X
  1397. X      Dispf(FALSE); Dispg(FALSE);
  1398. X
  1399. X      curtkey = mainKbd + offset + key; /* find address of (eventually shifted) key */
  1400. X
  1401. X      switch (curtkey->Sort) {
  1402. X     case Action:
  1403. X        *code = curtkey->Act;
  1404. X        return(Action);
  1405. X     case Instruction:
  1406. X        *code = curtkey->Code;
  1407. X        return(Instruction);
  1408. X     case Prefix: /* Key is a prefix, execute corresponding routine */
  1409. X        RelKey();
  1410. X        ret = (*(curtkey->Suffix))(code);
  1411. X        if (ret != Invalid) return(ret); /* if successful */
  1412. X
  1413. X        key = *code; /* else, invalid keycode returnedin code field for reuse */
  1414. X        noKey = FALSE; /* a key is already available */
  1415. X        break;
  1416. X     case Invalid: /* An inavlid f or g sequence was entered, retry it with
  1417. X        the f or g prefix stripped. Therefore all obtainable main keyboard sequences
  1418. X        must exist, otherwise the program enters an infinite loop retrying constantly
  1419. X        the same nonexistent keycode */
  1420. X        key %= NUMKEYS;
  1421. X        noKey = FALSE;
  1422. X        break;
  1423. X      }
  1424. X   }
  1425. X}
  1426. X
  1427. X/* Return position n on the liquid cristal display in string t */
  1428. Xint scrpos(t, n)
  1429. Xchar *t;
  1430. Xregister int n;
  1431. X{
  1432. X   register char *s = t;
  1433. X   register int pos;
  1434. X
  1435. X   pos = 0;
  1436. X   while (pos <= n && *s) { /* go on till end of string or beyond position n on display */
  1437. X      if (*s != '.' && *s != ',') pos++; /* . & , take no space on the display */
  1438. X      s++;
  1439. X   }
  1440. X   return((int)((s - t) - 1 - (pos - n))); /* pos - n  is there to take care of the overshoot. If
  1441. X   n is beyond the end of the string, the position returned may well be wildly beyond the
  1442. X   actual end of the string */
  1443. X}
  1444. X
  1445. X/* Return the length taken up on the screen by the string */
  1446. Xint scrlen(s)
  1447. Xregister char *s;
  1448. X{
  1449. X   register int cnt = 0;
  1450. X
  1451. X   while (*s) {
  1452. X      if (*s != '.' && *s != ',') cnt++; /* . & , take no space on the display */
  1453. X      s++;
  1454. X   }
  1455. X
  1456. X   return(cnt);
  1457. X}
  1458. X
  1459. X/* format string s in hp11 display format (without exponent) so that it takes
  1460. X n spaces in the display. s isn't modified */
  1461. Xstatic char *CvtStd(char *s, int n)
  1462. X{
  1463. X   static char buf[20];
  1464. X   register char *p;
  1465. X   register int i, nb;
  1466. X   register int digit_separator = comma ? '.' : ','; /* separator according to current setting */
  1467. X
  1468. X   strcpy(buf, s); /* copy string to safe work buffer */
  1469. X
  1470. X   if ((p = strchr(buf, '.')) == NULL) { /* find position of . */
  1471. X      p = buf + strlen(buf);
  1472. X      if (!entering) *p = comma ? ',' : '.';
  1473. X      *(p + 1) = '\0';
  1474. X   }
  1475. X   else if (comma) *p = ','; /* Replace . by , if necessary */
  1476. X
  1477. X   while ((p -= 3) - buf > 1) /* Add , (or .) to string every 3 digits */
  1478. X      stpich(p, digit_separator);
  1479. X
  1480. X   nb = n - scrlen(buf);
  1481. X   for (i = 1; i <= nb; i++) strcat(buf, " "); /* pad with spaces to required screen length */
  1482. X   buf[scrpos(buf, n) + 1] = '\0'; /* cut at n characters */
  1483. X
  1484. X   return(buf);
  1485. X}
  1486. X
  1487. X/* format string s in hp11 display format (with exponent) */
  1488. Xstatic char *CvtExpo(char *s, char *e)
  1489. X{
  1490. X   if (strlen(e) > 3) { /* deal with roundoff towards 1e100 when nb too big */
  1491. X      e = " 99"; /* exponent is 99 */
  1492. X      strncpy(s + 1, "9.999999999", strlen(s + 1)); /* mantissa is enough 9's */
  1493. X   }
  1494. X
  1495. X   return(strcat(CvtStd(s, 8), e));
  1496. X}
  1497. X
  1498. X/* convert x to scientific format with n digits. Returns it in a static buffer (from CvtStd) */
  1499. Xstatic char *Scient(double x, int n)
  1500. X{
  1501. X   char buf[20];
  1502. X   register char *pe;
  1503. X
  1504. X   sprintf(buf, "% .*E", n, x); /* Scientific format with n digits */
  1505. X   pe = strchr(buf, 'E'); /* split string into mantissa & exponent */
  1506. X   *pe++ = '\0';
  1507. X   /* if (*pe == '+') *pe = ' '; A + is displayed as a space by the Display routine anyway */
  1508. X
  1509. X   return(CvtExpo(buf, pe));
  1510. X}
  1511. X
  1512. X/* Convert x to fix n format */
  1513. Xstatic char *Fixed(double x, int n)
  1514. X{
  1515. X   char buf[80];
  1516. X
  1517. X   sprintf(buf, "% .*f", n, x);
  1518. X
  1519. X   return(CvtStd(buf, 11));
  1520. X}
  1521. X
  1522. X/* Eng n format */
  1523. Xstatic char *Engin(double x, int n)
  1524. X{
  1525. X   char expbuf[10], buf[80];
  1526. X   register char *pe;
  1527. X   double mantissa;
  1528. X   register int exponent, dif;
  1529. X
  1530. X   sprintf(buf, "%.*E", n, x); /* print enough digits */
  1531. X   *(pe = strchr(buf, 'E')) = '\0';
  1532. X   mantissa = atof(buf); /* get mantissa & exponent */
  1533. X   exponent = atoi(pe + 1);
  1534. X
  1535. X   /* Round exponent down to a multiple of 3 */
  1536. X   dif = exponent % 3;
  1537. X   if (dif < 0) dif += 3;
  1538. X   exponent -= dif; /* calculate new exponent & mantissa */
  1539. X   mantissa *= pow(10.0, (double)dif);
  1540. X
  1541. X   /* Convert them to string */
  1542. X   sprintf(buf, "% .*f", (n - dif > 0) ? n - dif : 0, mantissa);
  1543. X   sprintf(expbuf, "%c%02d", (exponent < 0) ? '-' : ' ', iabs(exponent)); /* pad exponent with 0's, hence %02d not %2d */
  1544. X
  1545. X   return(CvtExpo(buf, expbuf));
  1546. X}
  1547. X
  1548. X/* Display current trig mode */
  1549. Xstatic void DispAngle(void)
  1550. X{
  1551. X   switch (Angles) {
  1552. X      case grad:DispG(TRUE);
  1553. X      case rad:DispRAD(TRUE);
  1554. X      case deg:break;
  1555. X   }
  1556. X}
  1557. X
  1558. X/* Display current x value in normal mode, running in run mode */
  1559. Xvoid Disp()
  1560. X{
  1561. X   static int runcnt = MAXRUN;
  1562. X   static BOOL runon;
  1563. X
  1564. X   if (running) { /* Flash running on and off every MAXRUN calls */
  1565. X      if (fast) { /* Display Running only once in fast mode */
  1566. X     if (!runon) {
  1567. X        Display("  Running");
  1568. X        runon = TRUE; /* Running displayed */
  1569. X     }
  1570. X      }
  1571. X      else if (runcnt-- == 0) Display("");
  1572. X      else if (runcnt <= -MAXRUN) {
  1573. X     runcnt = MAXRUN;
  1574. X     Display("  Running");
  1575. X      }
  1576. X   }
  1577. X   else {
  1578. X      runon = FALSE; /* Running not displayed */
  1579. X      if (entering) /* Display number entry strings */
  1580. X     if (expo) Display(CvtExpo(strx, expx)); /* with exponent */
  1581. X     else Display(CvtStd(strx, 11));
  1582. X      else
  1583. X     Display(NbStr(X));
  1584. X
  1585. X      DispAngle();
  1586. X      if (User) DispUSER(TRUE);
  1587. X   }
  1588. X}
  1589. X
  1590. Xchar *NbStr(x)
  1591. Xdouble x;
  1592. X{
  1593. X   switch (Mode) { /* Display x according to display mode */
  1594. X      case fix:if ((fabs(X) >= minfix / 2.0 || X == 0.0) && fabs(X) < 1E10) {
  1595. X          /* Number can be displayed in fix mode */
  1596. X          return(Fixed(X, Digits));
  1597. X           }
  1598. X           /* fall through for call to Scient */
  1599. X      case sci:return(Scient(X, Digits));
  1600. X      case eng:return(Engin(X, Digits));
  1601. X   }
  1602. X}
  1603. X
  1604. X/* Display Error n, & wait for a key to be pressed */
  1605. Xvoid Error(n)
  1606. Xint n;
  1607. X{
  1608. X   register char *buf;
  1609. X
  1610. X   entering = FALSE; /* end of digit entry */
  1611. X   error = TRUE; /* an error has occured */
  1612. X   buf = "  Error  ";
  1613. X   buf[8] = n; buf[9] ='\0';
  1614. X
  1615. X   if (!running) RelKey();
  1616. X   Display(buf);
  1617. X   GetKey();
  1618. X
  1619. X}
  1620. X
  1621. X/* Display current program line */
  1622. Xvoid DisplayLine()
  1623. X{
  1624. X   register int c1 = keycodes[Prog[PC]].c1, c2 = keycodes[Prog[PC]].c2,
  1625. X        c3 = keycodes[Prog[PC]].c3;
  1626. X   char _buf[20], _insbuf[20];
  1627. X   register char *buf = _buf, *insbuf = _insbuf;
  1628. X   register int point = comma ? ',' : '.'; /* separator according to current setting */
  1629. X
  1630. X   sprintf(buf, " %03d-", PC); /* prepare program line */
  1631. X
  1632. X   /* Prepare instruction buffer */
  1633. X   if (PC == 0) insbuf[0] = '\0'; /* nothing at line 0 */
  1634. X   else switch (keycodes[Prog[PC]].Type) { /* there are 6 methods for displaying a line */
  1635. X      case ONECODE: sprintf(insbuf, "%6d", c1); break; /*     nn eg SIN or 9 */
  1636. X      case TWOCODE: sprintf(insbuf, "%3d%3d", c1, c2); break; /*  nn nn eg g LOG */
  1637. X      case TWOCODE_9: sprintf(insbuf, "%4d%2d", c1, c2); break; /*  nn n eg STO 5*/
  1638. X      case TWOCODE_PT: sprintf(insbuf, "%4d %c%1d", c1, point, c2); break; /* nn .n eg RCL .6 */
  1639. X      case THREECODE: sprintf(insbuf, "%2d,%2d,%2d", c1, c2, c3); break; /* nn,nn,nn eg f HYP SIN */
  1640. X      case THREECODE_PT: sprintf(insbuf, "%2d,%2d, %c%1d", c1, c2, point, c3); break; /* nn,nn, .n eg STO + .0 */
  1641. X   }
  1642. X
  1643. X   Display(strcat(buf, insbuf));
  1644. X
  1645. X   DispAngle();
  1646. X   if (User) DispUSER(TRUE);
  1647. X}
  1648. X
  1649. SHAR_EOF
  1650. echo "extracting io.h"
  1651. sed 's/^X//' << \SHAR_EOF > io.h
  1652. Xextern int comma; /* The current comma setting : true if decimal point is a comma,
  1653. X false if it is a point */
  1654. X
  1655. Xenum KeyTypes ReadKey(WORD *); /* Read a complete key sequence */
  1656. Xvoid Disp(void); /* Display the current value of X register */
  1657. Xvoid Error(int); /* Display Error n */
  1658. Xint GetKey(void); /* Read a key from the HP11 (waiting for its release) */
  1659. Xint scrpos(char *, int); /* Return position n on the liquid cristal display in string t */
  1660. Xint scrlen(char *); /* Return the length taken up on the screen by the string */
  1661. Xvoid DisplayLine(void); /* Display current program line */
  1662. Xchar *NbStr(double); /* Convert number into string according to current mode */
  1663. SHAR_EOF
  1664. echo "extracting kbd.c"
  1665. sed 's/^X//' << \SHAR_EOF > kbd.c
  1666. X#include "exec/types.h"
  1667. X#include "hp11/hp11.h"
  1668. X#include "hp11/kbd.h"
  1669. X#include "hp11/codes.h"
  1670. X#include "hp11/io.h"
  1671. X
  1672. X/* Macros to initialise one field of the keyboard structure to a particular type.
  1673. X  This simpilfies (& clarifies) this initialisation. */
  1674. X#define CODE(code) {Instruction, (Decoder)(code) }
  1675. X#define ACT(act) {Action, (Decoder)(act) }
  1676. X#define PREFIX(adr) {Prefix, (adr) }
  1677. X#define INVALID() {Invalid, NULL }
  1678. X
  1679. X/* Often used macros which return their agument signaling that it is an instruction,
  1680. X  action or error */
  1681. X#define RETINS(val) { *code = (val); return(Instruction); }
  1682. X#define RETACT(val) { *code = (val); return(Action); }
  1683. X#define RETERR(key) { *code = (key); return(Invalid); }
  1684. X
  1685. X/* Keys which can follow GTO (or GSB). A -1 indicates am invalid sequence, otherwise
  1686. X  the value is the offset to add to KGTO to obtain the corresponding instruction.
  1687. X  IGTO_LINE is different and valid only for GTO, it indicates a GTO .nnn action */
  1688. Xstatic BYTE gto_decode[NUMKEYS] = {
  1689. X   10, 11, 12, 13, 14, -1, 7, 8, 9, -1,
  1690. X   -1, -1, -1, -1, OIND_G, -1, 4, 5, 6, -1,
  1691. X   -1, -1, -1, -1, -1, -1, 1, 2, 3, -1,
  1692. X   -1, -1, -1, -1, -1, -1, 0, IGTO_LINE, -1, -1,
  1693. X   -1, -1
  1694. X};
  1695. X
  1696. X/* For STO & RCL, cf above */
  1697. Xstatic BYTE sto_decode[NUMKEYS] = {
  1698. X   -1, -1, -1, -1, -1, -1, 7, 8, 9, ODIV,
  1699. X   -1, -1, -1, OIND_R, OI, -1, 4, 5, 6, OMUL,
  1700. X   -1, -1, -1, -1, -1, KRANDOM, 1, 2, 3, OSUB,
  1701. X   -1, -1, -1, -1, -1, -1, 0, KPOINT, KSIGMA_PLUS, OPLUS,
  1702. X   -1, -1
  1703. X};
  1704. X
  1705. X/* Functions which take a numeric argument only (eg eng) can use the numbers
  1706. X  from gto_decode, considering as invalid what isn't a number between 1 & 10 */
  1707. X#define nb_decode gto_decode
  1708. X
  1709. X/* Read 3 digits for GTO .nnn & return the value in line. If something other than
  1710. X  a number is entered, return the keycode of the first incorrect code & FALSE */
  1711. Xstatic BOOL GetLine(short *line)
  1712. X{
  1713. X   register int cnt = 0, key;
  1714. X   register int dec;
  1715. X
  1716. X   *line = 0;
  1717. X
  1718. X   do {
  1719. X      key = GetKey(); dec = nb_decode[key]; /* Get numeric value */
  1720. X      if (dec >= 0 && dec <= 9) { /* It is a digit */
  1721. X     cnt++;
  1722. X     *line = *line * 10 + dec;
  1723. X      }
  1724. X      else { /* error */
  1725. X     *line = key;
  1726. X     return(FALSE);
  1727. X      }
  1728. X   } while (cnt < 3);
  1729. X
  1730. X   /* 3 digits reads */
  1731. X   return(TRUE);
  1732. X}
  1733. X
  1734. X/* Decoder routine for FIX, SCI, ENG, SF, CF, Set. code returns the
  1735. X  instruction/action/keycode, start is the offset for the instruction being
  1736. X  decoded (eg KFIX), max is the maximum value which can be accepted (eg 1 for SF).
  1737. X  For SCI & ENG, a number beyond their max (7) is treated as if it was the max
  1738. X  value (So if you type 'f SCI 8' you will get 'f SCI 7' */
  1739. Xstatic enum KeyTypes NBDec(short *code, int start, int max)
  1740. X{
  1741. X   register int key, dec;
  1742. X
  1743. X   key = GetKey(); dec = nb_decode[key];
  1744. X
  1745. X   if (dec >= 0 && dec <= 9) { /* Is a digit */
  1746. X      if (dec <= max) RETINS(start + dec) /* valid ins */
  1747. X      else if (start == KSCI || start == KENG) RETINS(start + max)
  1748. X     /* Special treatment for SCI & ENG */
  1749. X   }
  1750. X   RETERR(key);
  1751. X}
  1752. X
  1753. X/* Decoding for HYP & ArcHYP */
  1754. Xstatic enum KeyTypes HypDec(short *code, int start)
  1755. X{
  1756. X   int key;
  1757. X
  1758. X   key = GetKey();
  1759. X   if (key >= 12 /* SIN */ && key <= 14 /* TAN */) RETINS(start + key - 12)
  1760. X   else RETERR(key);
  1761. X}
  1762. X
  1763. X/* Decoding for GTO, GSB & LBL */
  1764. Xstatic enum KeyTypes JMPDec(short *code, int start)
  1765. X{
  1766. X   register int key, dec;
  1767. X   short val;
  1768. X
  1769. X   key = GetKey(); dec = gto_decode[key];
  1770. X
  1771. X   if (dec >= 0 && dec <= 15) RETINS(start + dec); /* 0 to 9, A to E */
  1772. X   switch (dec) {
  1773. X      case IGTO_LINE: if (start == KGTO) /* GTO .nnn */
  1774. X     if (GetLine(&val)) RETACT(IGTO_LINE + val)
  1775. X     else RETERR(val);
  1776. X      case OIND_G: if (start != KLBL) RETINS(start + OIND_G); /* GTO/GSB I */
  1777. X   }
  1778. X   RETERR(key);
  1779. X}
  1780. X
  1781. X/* Decoding for STO & RCL, deals with all possible STO's */
  1782. Xstatic enum KeyTypes REGDec(short *code, int start)
  1783. X{
  1784. X   register int dec, key, oldoff, offset = 0;
  1785. X
  1786. X   do {
  1787. X      key = GetKey();
  1788. X      dec = sto_decode[key];
  1789. X      oldoff = offset;
  1790. X
  1791. X      if ((dec >= 0 && dec <= 9) /* 0 to 9 end an instruction */
  1792. X      || /* I & (i) end an instruction if no . was typed before. This
  1793. X           is visible if the offset (ignoring + - * /) is 10 */
  1794. X      ((offset % OPLUS) != 10 && (dec == OI || dec == OIND_R)))
  1795. X     RETINS(start + offset + dec);
  1796. X      switch (dec) { /* Special cases & offsets */
  1797. X     case KRANDOM: if (offset == 0 && start == KSTO) RETINS(KSTO_RANDOM); /* STO Random */
  1798. X     case KSIGMA_PLUS: if (offset == 0 && start == KRCL) RETINS(KRCL_SIGMA); /* Recall stats */
  1799. X     case KPOINT: if ((offset % OPLUS) == 0) offset += 10; /* Only one . allowed */
  1800. X     case OPLUS: case ODIV: case OMUL: case OSUB: /* + - * / only if none yet */
  1801. X        if (offset == 0 && start == KSTO) offset = dec;
  1802. X      }
  1803. X   } while (offset != oldoff);
  1804. X   /* if offset not changed then there was an error (the loop is repeated when
  1805. X      the offset changes) */
  1806. X   RETERR(key);
  1807. X}
  1808. X
  1809. X/* Decoding for prefixes */
  1810. X/* --------------------- */
  1811. Xstatic enum KeyTypes FIXDec(short *code)
  1812. X{
  1813. X   return(NBDec(code, KFIX, 9));
  1814. X}
  1815. X
  1816. Xstatic enum KeyTypes SCIDec(short *code)
  1817. X{
  1818. X   return(NBDec(code, KSCI, 7));
  1819. X}
  1820. X
  1821. Xstatic enum KeyTypes ENGDec(short *code)
  1822. X{
  1823. X   return(NBDec(code, KENG, 7));
  1824. X}
  1825. X
  1826. Xstatic enum KeyTypes SFDec(short *code)
  1827. X{
  1828. X   return(NBDec(code, KFLAGS + OSF, 1));
  1829. X}
  1830. X
  1831. Xstatic enum KeyTypes SETDec(short *code)
  1832. X{
  1833. X   return(NBDec(code, KFLAGS + OSET, 1));
  1834. X}
  1835. X
  1836. Xstatic enum KeyTypes CFDec(short *code)
  1837. X{
  1838. X   return(NBDec(code, KFLAGS + OCF, 1));
  1839. X}
  1840. X
  1841. Xstatic enum KeyTypes HYPDec(short *code)
  1842. X{
  1843. X   return(HypDec(code, KHYP));
  1844. X}
  1845. X
  1846. Xstatic enum KeyTypes ARCHYPDec(short *code)
  1847. X{
  1848. X   return(HypDec(code, KARCHYP));
  1849. X}
  1850. X
  1851. Xstatic enum KeyTypes LBLDec(short *code)
  1852. X{
  1853. X   return(JMPDec(code, KLBL));
  1854. X}
  1855. X
  1856. Xstatic enum KeyTypes GTODec(short *code)
  1857. X{
  1858. X   return(JMPDec(code, KGTO));
  1859. X}
  1860. X
  1861. Xstatic enum KeyTypes GSBDec(short *code)
  1862. X{
  1863. X   return(JMPDec(code, KGSB));
  1864. X}
  1865. X
  1866. Xstatic enum KeyTypes STODec(short *code)
  1867. X{
  1868. X   return(REGDec(code, KSTO));
  1869. X}
  1870. X
  1871. Xstatic enum KeyTypes RCLDec(short *code)
  1872. X{
  1873. X   return(REGDec(code, KRCL));
  1874. X}
  1875. X
  1876. X/* The main kbd, f & g */
  1877. X/* ------------------- */
  1878. Xstruct Key mainKbd[3 * NUMKEYS] = {
  1879. X/* First the main keyboard (unshifted). All the keys which can be entered
  1880. X  MUST not be INVALID(), otherwise the program enters an infinite loop */
  1881. X   CODE(KSQRT),
  1882. X   CODE(KEXP),
  1883. X   CODE(KEXP10),
  1884. X   CODE(KEXP_YX),
  1885. X   CODE(KINV),
  1886. X   CODE(KCHS),
  1887. X   CODE(KFIG + 7),
  1888. X   CODE(KFIG + 8),
  1889. X   CODE(KFIG + 9),
  1890. X   CODE(KDIV),
  1891. X   ACT(ISST),
  1892. X   PREFIX(GTODec),
  1893. X   CODE(KTRIG + OSIN),
  1894. X   CODE(KTRIG + OCOS),
  1895. X   CODE(KTRIG + OTAN),
  1896. X   CODE(KEEX),
  1897. X   CODE(KFIG + 4),
  1898. X   CODE(KFIG + 5),
  1899. X   CODE(KFIG + 6),
  1900. X   CODE(KMUL),
  1901. X   CODE(KR_S),
  1902. X   PREFIX(GSBDec),
  1903. X   CODE(KRDN),
  1904. X   CODE(KEXG_XY),
  1905. X   ACT(IBACK),
  1906. X   CODE(KENTER),
  1907. X   CODE(KFIG + 1),
  1908. X   CODE(KFIG + 2),
  1909. X   CODE(KFIG + 3),
  1910. X   CODE(KSUB),
  1911. X   ACT(ION),
  1912. X   INVALID(), /* Never tested : f */
  1913. X   INVALID(), /* Never tested : g */
  1914. X   PREFIX(STODec),
  1915. X   PREFIX(RCLDec),
  1916. X   INVALID(), /* This key does not exist : it is hidden by ENTER */
  1917. X   CODE(KFIG + 0),
  1918. X   CODE(KPOINT),
  1919. X   CODE(KSIGMA_PLUS),
  1920. X   CODE(KPLUS),
  1921. X   ACT(IRESET), /* These 2 are pseudo-keys */
  1922. X   ACT(IDISPLAY),
  1923. X/* now f codes, which can be INVALID() */
  1924. X   CODE(KGSB + OA),
  1925. X   CODE(KGSB + OB),
  1926. X   CODE(KGSB + OC),
  1927. X   CODE(KGSB + OD),
  1928. X   CODE(KGSB + OE),
  1929. X   CODE(KPI),
  1930. X   PREFIX(FIXDec),
  1931. X   PREFIX(SCIDec),
  1932. X   PREFIX(ENGDec),
  1933. X   CODE(KX_LE_Y),
  1934. X   PREFIX(LBLDec),
  1935. X   PREFIX(HYPDec),
  1936. X   CODE(KEXG_X_IND),
  1937. X   CODE(KRCL + OIND_R),
  1938. X   CODE(KRCL + OI),
  1939. X   CODE(KRECT),
  1940. X   CODE(KEXG_XI),
  1941. X   CODE(KDSE),
  1942. X   CODE(KISG),
  1943. X   CODE(KX_GT_Y),
  1944. X   CODE(KPSE),
  1945. X   CODE(KCLR_SIGMA),
  1946. X   ACT(ICLR_PRGM),
  1947. X   CODE(KCLR_REG),
  1948. X   ACT(ICLR_PREFIX),
  1949. X   CODE(KRANDOM),
  1950. X   CODE(KPERM),
  1951. X   CODE(KHMS),
  1952. X   CODE(KTO_RAD),
  1953. X   CODE(KX_NE_Y),
  1954. X   INVALID(), INVALID(), INVALID(), /* ON, f & g */
  1955. X   CODE(KFRAC),
  1956. X   ACT(IUSER),
  1957. X   INVALID(), /* dosen't exist */
  1958. X   CODE(KFACT),
  1959. X   CODE(KESTIMATE),
  1960. X   CODE(KLR),
  1961. X   CODE(KX_EQ_Y),
  1962. X   INVALID(), INVALID(),
  1963. X/* finally, g codes */
  1964. X   CODE(KSQR),
  1965. X   CODE(KLN),
  1966. X   CODE(KLOG),
  1967. X   CODE(KPERC),
  1968. X   CODE(KDELTA_PERC),
  1969. X   CODE(KABS),
  1970. X   CODE(KDEG),
  1971. X   CODE(KRAD),
  1972. X   CODE(KGRD),
  1973. X   CODE(KX_LT_0),
  1974. X   ACT(IBST),
  1975. X   PREFIX(ARCHYPDec),
  1976. X   CODE(KARC + OSIN),
  1977. X   CODE(KARC + OCOS),
  1978. X   CODE(KARC + OTAN),
  1979. X   CODE(KPOLAR),
  1980. X   PREFIX(SFDec),
  1981. X   PREFIX(CFDec),
  1982. X   PREFIX(SETDec),
  1983. X   CODE(KX_GT_0),
  1984. X   ACT(IP_R),
  1985. X   CODE(KRTN),
  1986. X   CODE(KRUP),
  1987. X   CODE(KRND),
  1988. X   CODE(KCLX),
  1989. X   CODE(KLSTX),
  1990. X   CODE(KCOMB),
  1991. X   CODE(KHR),
  1992. X   CODE(KTO_DEG),
  1993. X   CODE(KX_NE_0),
  1994. X   INVALID(), INVALID(), INVALID(),
  1995. X   CODE(KINT),
  1996. X   ACT(IMEM),
  1997. X   INVALID(),
  1998. X   CODE(KMEAN),
  1999. X   CODE(KSDEV),
  2000. X   CODE(KSIGMA_SUB),
  2001. X   CODE(KX_EQ_0),
  2002. X   INVALID(), INVALID()
  2003. X};
  2004. X
  2005. SHAR_EOF
  2006. echo "extracting kbd.h"
  2007. sed 's/^X//' << \SHAR_EOF > kbd.h
  2008. X/* Define type Decoder which is a function with a short * argument and which
  2009. X  return an enum KeyTypes. These functions do the keyboard decoding for prefixes */
  2010. Xtypedef enum KeyTypes (*Decoder)(short *);
  2011. X
  2012. X/* One key of the keyboard structure : */
  2013. Xstruct Key {
  2014. X   enum KeyTypes Sort; /* The type of key */
  2015. X   union { /* Different data for each type */
  2016. X      Decoder suffix; /* Prefix ==> decoder function */
  2017. X      LONG act; /* Action number */
  2018. X      LONG code; /* Instruction number */
  2019. X   } Data;
  2020. X};
  2021. X
  2022. X/* These defines are done to simplify access to the components */
  2023. X#define Act Data.act
  2024. X#define Code Data.code
  2025. X#define Suffix Data.suffix
  2026. X
  2027. Xextern struct Key mainKbd[3 * NUMKEYS]; /* The main, f & g key sequences */
  2028. SHAR_EOF
  2029. echo "extracting lmkdebug"
  2030. sed 's/^X//' << \SHAR_EOF > lmkdebug
  2031. XFLAGS = -v -cf -rr -ilcc: -d5
  2032. XFLAGS2 = -Hinclude:small.sym $(FLAGS)
  2033. XOBJ = od/
  2034. X
  2035. X.c.o:
  2036. X  lc $(FLAGS) -o$(OBJ) $*
  2037. X
  2038. Xhp11: $(OBJ)hp11.o $(OBJ)io.o $(OBJ)ins.o $(OBJ)kbd.o $(OBJ)prog_codes.o \
  2039. X      $(OBJ)support.o $(OBJ)indic.o $(OBJ)chip.o $(OBJ)menus.o $(OBJ)icon.o \
  2040. X      $(OBJ)amiga.o $(OBJ)chars.o
  2041. X    blink with hp11.debug
  2042. X
  2043. X$(OBJ)hp11.o: hp11.c hp11.h amiga/amiga.h io.h support.h ins.h codes.h
  2044. X
  2045. X$(OBJ)io.o: io.c hp11.h amiga/amiga.h ins.h io.h kbd.h codes.h prog_codes.h
  2046. X
  2047. X$(OBJ)ins.o: ins.c amiga/amiga.h hp11.h io.h support.h ins.h codes.h
  2048. X
  2049. X$(OBJ)kbd.o: kbd.c hp11.h kbd.h codes.h io.h
  2050. X
  2051. X$(OBJ)prog_codes.o: prog_codes.c prog_codes.h
  2052. X
  2053. X$(OBJ)support.o: support.c support.h
  2054. X
  2055. X$(OBJ)chars.o: amiga/chars.c
  2056. X  lc $(FLAGS2) -o$(OBJ) $*
  2057. X
  2058. X$(OBJ)indic.o: amiga/indic.c
  2059. X  lc $(FLAGS2) -o$(OBJ) $*
  2060. X
  2061. X$(OBJ)chip.o: amiga/chip.c
  2062. X  lc $(FLAGS2) -o$(OBJ) $*
  2063. X
  2064. X$(OBJ)menus.o: amiga/menus.c hp11.h io.h ins.h amiga/menus.h amiga/internal.h amiga/cbio.h
  2065. X  lc $(FLAGS2) -o$(OBJ) $*
  2066. X
  2067. X$(OBJ)icon.o: amiga/icon.c
  2068. X# Should be same as other amiga routines, but there is a bug ...
  2069. X
  2070. X$(OBJ)amiga.o: amiga/amiga.c hp11.h amiga/internal.h amiga/amiga.h amiga/menus.h
  2071. X  lc $(FLAGS2) -o$(OBJ) $*
  2072. X
  2073. SHAR_EOF
  2074. echo "extracting lmkfile"
  2075. sed 's/^X//' << \SHAR_EOF > lmkfile
  2076. XFLAGS = -v -cf -m1s -O -ilcc: -rr
  2077. XFLAGS2 = $(FLAGS)
  2078. XOBJ = o/
  2079. X
  2080. X.c.o:
  2081. X  lc $(FLAGS) -o$(OBJ) $*
  2082. X
  2083. Xhp11: $(OBJ)hp11.o $(OBJ)io.o $(OBJ)ins.o $(OBJ)kbd.o $(OBJ)prog_codes.o \
  2084. X      $(OBJ)support.o $(OBJ)indic.o $(OBJ)chip.o $(OBJ)menus.o $(OBJ)icon.o \
  2085. X      $(OBJ)amiga.o $(OBJ)chars.o
  2086. X    blink with hp11.lnk
  2087. X
  2088. X$(OBJ)hp11.o: hp11.c hp11.h amiga/amiga.h io.h support.h ins.h codes.h
  2089. X
  2090. X$(OBJ)io.o: io.c hp11.h amiga/amiga.h ins.h io.h kbd.h codes.h prog_codes.h
  2091. X
  2092. X$(OBJ)ins.o: ins.c amiga/amiga.h hp11.h io.h support.h ins.h codes.h
  2093. X
  2094. X$(OBJ)kbd.o: kbd.c hp11.h kbd.h codes.h io.h
  2095. X
  2096. X$(OBJ)prog_codes.o: prog_codes.c prog_codes.h
  2097. X
  2098. X$(OBJ)support.o: support.c support.h
  2099. X
  2100. X$(OBJ)chars.o: amiga/chars.c
  2101. X  lc $(FLAGS2) -o$(OBJ) $*
  2102. X
  2103. X$(OBJ)indic.o: amiga/indic.c
  2104. X  lc $(FLAGS2) -o$(OBJ) $*
  2105. X
  2106. X$(OBJ)chip.o: amiga/chip.c
  2107. X  lc $(FLAGS2) -o$(OBJ) $*
  2108. X
  2109. X$(OBJ)menus.o: amiga/menus.c hp11.h io.h ins.h amiga/menus.h amiga/internal.h amiga/cbio.h
  2110. X  lc $(FLAGS2) -o$(OBJ) $*
  2111. X
  2112. X$(OBJ)icon.o: amiga/icon.c
  2113. X# Should be same as other amiga routines, but there is a bug ...
  2114. X
  2115. X$(OBJ)amiga.o: amiga/amiga.c hp11.h amiga/internal.h amiga/amiga.h amiga/menus.h
  2116. X  lc $(FLAGS2) -o$(OBJ) $*
  2117. X
  2118. SHAR_EOF
  2119. if `test ! -d o`
  2120. then
  2121.   mkdir o
  2122.   echo "mkdir o"
  2123. fi
  2124. echo "extracting o/dummy"
  2125. sed 's/^X//' << \SHAR_EOF > o/dummy
  2126. SHAR_EOF
  2127. if `test ! -d od`
  2128. then
  2129.   mkdir od
  2130.   echo "mkdir od"
  2131. fi
  2132. echo "extracting od/dummy"
  2133. sed 's/^X//' << \SHAR_EOF > od/dummy
  2134. SHAR_EOF
  2135. echo "extracting prog_codes.c"
  2136. sed 's/^X//' << \SHAR_EOF > prog_codes.c
  2137. X/* The actual codes used */
  2138. X#include "exec/types.h"
  2139. X
  2140. X#include "hp11/prog_codes.h"
  2141. X
  2142. X/* To decode an instruction, you use its code (from codes.h). Therefore,
  2143. X  if these are changed, you must change these keycodes as well */
  2144. Xstruct KeyCode keycodes[] = {
  2145. X   {ONECODE, 11},
  2146. X   {ONECODE, 12},
  2147. X   {ONECODE, 13},
  2148. X   {ONECODE, 14},
  2149. X   {ONECODE, 15},
  2150. X   {ONECODE, 16},
  2151. X   {ONECODE, 10},
  2152. X   {ONECODE, 23},
  2153. X   {ONECODE, 24},
  2154. X   {ONECODE, 25},
  2155. X   {ONECODE, 26},
  2156. X   {ONECODE, 20},
  2157. X   {ONECODE, 31},
  2158. X   {ONECODE, 33},
  2159. X   {ONECODE, 34},
  2160. X   {ONECODE, 36},
  2161. X   {ONECODE, 30},
  2162. X   {ONECODE, 48},
  2163. X   {ONECODE, 49},
  2164. X   {ONECODE, 40},
  2165. X/* f codes */
  2166. X   {TWOCODE, 42, 16},
  2167. X   {TWOCODE, 42, 10},
  2168. X   {TWOCODE, 42, 23},
  2169. X   {TWOCODE, 42, 26},
  2170. X   {TWOCODE_9, 42, 4},
  2171. X   {TWOCODE_9, 42, 5},
  2172. X   {TWOCODE_9, 42, 6},
  2173. X   {TWOCODE, 42, 20},
  2174. X   {TWOCODE, 42, 31},
  2175. X   {TWOCODE, 42, 32},
  2176. X   {TWOCODE, 42, 34},
  2177. X   {TWOCODE, 42, 36},
  2178. X   {TWOCODE_9, 42, 1},
  2179. X   {TWOCODE_9, 42, 2},
  2180. X   {TWOCODE_9, 42, 3},
  2181. X   {TWOCODE, 42, 30},
  2182. X   {TWOCODE, 42, 44},
  2183. X   {TWOCODE_9, 42,0},
  2184. X   {TWOCODE, 42, 48},
  2185. X   {TWOCODE, 42, 49},
  2186. X   {TWOCODE, 42, 40},
  2187. X/* g codes */
  2188. X   {TWOCODE, 43, 11},
  2189. X   {TWOCODE, 43, 12},
  2190. X   {TWOCODE, 43, 13},
  2191. X   {TWOCODE, 43, 14},
  2192. X   {TWOCODE, 43, 15},
  2193. X   {TWOCODE, 43, 16},
  2194. X   {TWOCODE_9, 43, 7},
  2195. X   {TWOCODE_9, 43, 8},
  2196. X   {TWOCODE_9, 43, 9},
  2197. X   {TWOCODE, 43, 10},
  2198. X   {TWOCODE, 43, 23},
  2199. X   {TWOCODE, 43, 24},
  2200. X   {TWOCODE, 43, 25},
  2201. X   {TWOCODE, 43, 26},
  2202. X   {TWOCODE, 43, 20},
  2203. X   {TWOCODE, 43, 32},
  2204. X   {TWOCODE, 43, 33},
  2205. X   {TWOCODE, 43, 34},
  2206. X   {TWOCODE, 43, 35},
  2207. X   {TWOCODE, 43, 36},
  2208. X   {TWOCODE_9, 43, 1},
  2209. X   {TWOCODE_9, 43, 2},
  2210. X   {TWOCODE_9, 43, 3},
  2211. X   {TWOCODE, 43, 30},
  2212. X   {TWOCODE, 43, 44},
  2213. X   {TWOCODE_9, 43, 0},
  2214. X   {TWOCODE, 43, 48},
  2215. X   {TWOCODE, 43, 49},
  2216. X   {TWOCODE, 43, 40},
  2217. X/* Miscellaneous */
  2218. X   {TWOCODE, 45, 36},
  2219. X   {TWOCODE, 45, 49},
  2220. X/* ARC */
  2221. X   {THREECODE, 42, 22, 23},
  2222. X   {THREECODE, 42, 22, 24},
  2223. X   {THREECODE, 42, 22, 25},
  2224. X   {THREECODE, 43, 22, 23},
  2225. X   {THREECODE, 43, 22, 24},
  2226. X   {THREECODE, 43, 22, 25},
  2227. X/* Flags */
  2228. X   {THREECODE, 43, 4, 0},
  2229. X   {THREECODE, 43, 4, 1},
  2230. X   {THREECODE, 43, 5, 0},
  2231. X   {THREECODE, 43, 5, 1},
  2232. X   {THREECODE, 43, 6, 0},
  2233. X   {THREECODE, 43, 6, 1},
  2234. X/* Figures */
  2235. X   {ONECODE, 0},
  2236. X   {ONECODE, 1},
  2237. X   {ONECODE, 2},
  2238. X   {ONECODE, 3},
  2239. X   {ONECODE, 4},
  2240. X   {ONECODE, 5},
  2241. X   {ONECODE, 6},
  2242. X   {ONECODE, 7},
  2243. X   {ONECODE, 8},
  2244. X   {ONECODE, 9},
  2245. X/* FIX, SCI, ENG */
  2246. X   {THREECODE, 42, 7, 0},
  2247. X   {THREECODE, 42, 7, 1},
  2248. X   {THREECODE, 42, 7, 2},
  2249. X   {THREECODE, 42, 7, 3},
  2250. X   {THREECODE, 42, 7, 4},
  2251. X   {THREECODE, 42, 7, 5},
  2252. X   {THREECODE, 42, 7, 6},
  2253. X   {THREECODE, 42, 7, 7},
  2254. X   {THREECODE, 42, 7, 8},
  2255. X   {THREECODE, 42, 7, 9},
  2256. X
  2257. X   {THREECODE, 42, 8, 0},
  2258. X   {THREECODE, 42, 8, 1},
  2259. X   {THREECODE, 42, 8, 2},
  2260. X   {THREECODE, 42, 8, 3},
  2261. X   {THREECODE, 42, 8, 4},
  2262. X   {THREECODE, 42, 8, 5},
  2263. X   {THREECODE, 42, 8, 6},
  2264. X   {THREECODE, 42, 8, 7},
  2265. X
  2266. X   {THREECODE, 42, 9, 0},
  2267. X   {THREECODE, 42, 9, 1},
  2268. X   {THREECODE, 42, 9, 2},
  2269. X   {THREECODE, 42, 9, 3},
  2270. X   {THREECODE, 42, 9, 4},
  2271. X   {THREECODE, 42, 9, 5},
  2272. X   {THREECODE, 42, 9, 6},
  2273. X   {THREECODE, 42, 9, 7},
  2274. X/* LBL, GTO, GSB */
  2275. X   {THREECODE, 42, 21, 0},
  2276. X   {THREECODE, 42, 21, 1},
  2277. X   {THREECODE, 42, 21, 2},
  2278. X   {THREECODE, 42, 21, 3},
  2279. X   {THREECODE, 42, 21, 4},
  2280. X   {THREECODE, 42, 21, 5},
  2281. X   {THREECODE, 42, 21, 6},
  2282. X   {THREECODE, 42, 21, 7},
  2283. X   {THREECODE, 42, 21, 8},
  2284. X   {THREECODE, 42, 21, 9},
  2285. X   {THREECODE, 42, 21, 11},
  2286. X   {THREECODE, 42, 21, 12},
  2287. X   {THREECODE, 42, 21, 13},
  2288. X   {THREECODE, 42, 21, 14},
  2289. X   {THREECODE, 42, 21, 15},
  2290. X
  2291. X   {TWOCODE_9, 22, 0},
  2292. X   {TWOCODE_9, 22, 1},
  2293. X   {TWOCODE_9, 22, 2},
  2294. X   {TWOCODE_9, 22, 3},
  2295. X   {TWOCODE_9, 22, 4},
  2296. X   {TWOCODE_9, 22, 5},
  2297. X   {TWOCODE_9, 22, 6},
  2298. X   {TWOCODE_9, 22, 7},
  2299. X   {TWOCODE_9, 22, 8},
  2300. X   {TWOCODE_9, 22, 9},
  2301. X   {TWOCODE, 22, 11},
  2302. X   {TWOCODE, 22, 12},
  2303. X   {TWOCODE, 22, 13},
  2304. X   {TWOCODE, 22, 14},
  2305. X   {TWOCODE, 22, 15},
  2306. X   {TWOCODE, 22, 25},
  2307. X
  2308. X   {TWOCODE_9, 32, 0},
  2309. X   {TWOCODE_9, 32, 1},
  2310. X   {TWOCODE_9, 32, 2},
  2311. X   {TWOCODE_9, 32, 3},
  2312. X   {TWOCODE_9, 32, 4},
  2313. X   {TWOCODE_9, 32, 5},
  2314. X   {TWOCODE_9, 32, 6},
  2315. X   {TWOCODE_9, 32, 7},
  2316. X   {TWOCODE_9, 32, 8},
  2317. X   {TWOCODE_9, 32, 9},
  2318. X   {TWOCODE, 32, 11},
  2319. X   {TWOCODE, 32, 12},
  2320. X   {TWOCODE, 32, 13},
  2321. X   {TWOCODE, 32, 14},
  2322. X   {TWOCODE, 32, 15},
  2323. X   {TWOCODE, 32, 25},
  2324. X/* STO, STO +, STO -, STO *, STO / */
  2325. X   {TWOCODE_9, 44, 0},
  2326. X   {TWOCODE_9, 44, 1},
  2327. X   {TWOCODE_9, 44, 2},
  2328. X   {TWOCODE_9, 44, 3},
  2329. X   {TWOCODE_9, 44, 4},
  2330. X   {TWOCODE_9, 44, 5},
  2331. X   {TWOCODE_9, 44, 6},
  2332. X   {TWOCODE_9, 44, 7},
  2333. X   {TWOCODE_9, 44, 8},
  2334. X   {TWOCODE_9, 44, 9},
  2335. X   {TWOCODE_PT, 44, 0},
  2336. X   {TWOCODE_PT, 44, 1},
  2337. X   {TWOCODE_PT, 44, 2},
  2338. X   {TWOCODE_PT, 44, 3},
  2339. X   {TWOCODE_PT, 44, 4},
  2340. X   {TWOCODE_PT, 44, 5},
  2341. X   {TWOCODE_PT, 44, 6},
  2342. X   {TWOCODE_PT, 44, 7},
  2343. X   {TWOCODE_PT, 44, 8},
  2344. X   {TWOCODE_PT, 44, 9},
  2345. X   {TWOCODE, 44, 25},
  2346. X   {TWOCODE, 44, 24},
  2347. X
  2348. X   {THREECODE, 44, 40, 0},
  2349. X   {THREECODE, 44, 40, 1},
  2350. X   {THREECODE, 44, 40, 2},
  2351. X   {THREECODE, 44, 40, 3},
  2352. X   {THREECODE, 44, 40, 4},
  2353. X   {THREECODE, 44, 40, 5},
  2354. X   {THREECODE, 44, 40, 6},
  2355. X   {THREECODE, 44, 40, 7},
  2356. X   {THREECODE, 44, 40, 8},
  2357. X   {THREECODE, 44, 40, 9},
  2358. X   {THREECODE_PT, 44, 40, 0},
  2359. X   {THREECODE_PT, 44, 40, 1},
  2360. X   {THREECODE_PT, 44, 40, 2},
  2361. X   {THREECODE_PT, 44, 40, 3},
  2362. X   {THREECODE_PT, 44, 40, 4},
  2363. X   {THREECODE_PT, 44, 40, 5},
  2364. X   {THREECODE_PT, 44, 40, 6},
  2365. X   {THREECODE_PT, 44, 40, 7},
  2366. X   {THREECODE_PT, 44, 40, 8},
  2367. X   {THREECODE_PT, 44, 40, 9},
  2368. X   {THREECODE, 44, 40, 25},
  2369. X   {THREECODE, 44, 40, 24},
  2370. X
  2371. X   {THREECODE, 44, 30, 0},
  2372. X   {THREECODE, 44, 30, 1},
  2373. X   {THREECODE, 44, 30, 2},
  2374. X   {THREECODE, 44, 30, 3},
  2375. X   {THREECODE, 44, 30, 4},
  2376. X   {THREECODE, 44, 30, 5},
  2377. X   {THREECODE, 44, 30, 6},
  2378. X   {THREECODE, 44, 30, 7},
  2379. X   {THREECODE, 44, 30, 8},
  2380. X   {THREECODE, 44, 30, 9},
  2381. X   {THREECODE_PT, 44, 30, 0},
  2382. X   {THREECODE_PT, 44, 30, 1},
  2383. X   {THREECODE_PT, 44, 30, 2},
  2384. X   {THREECODE_PT, 44, 30, 3},
  2385. X   {THREECODE_PT, 44, 30, 4},
  2386. X   {THREECODE_PT, 44, 30, 5},
  2387. X   {THREECODE_PT, 44, 30, 6},
  2388. X   {THREECODE_PT, 44, 30, 7},
  2389. X   {THREECODE_PT, 44, 30, 8},
  2390. X   {THREECODE_PT, 44, 30, 9},
  2391. X   {THREECODE, 44, 30, 25},
  2392. X   {THREECODE, 44, 30, 24},
  2393. X
  2394. X   {THREECODE, 44, 20, 0},
  2395. X   {THREECODE, 44, 20, 1},
  2396. X   {THREECODE, 44, 20, 2},
  2397. X   {THREECODE, 44, 20, 3},
  2398. X   {THREECODE, 44, 20, 4},
  2399. X   {THREECODE, 44, 20, 5},
  2400. X   {THREECODE, 44, 20, 6},
  2401. X   {THREECODE, 44, 20, 7},
  2402. X   {THREECODE, 44, 20, 8},
  2403. X   {THREECODE, 44, 20, 9},
  2404. X   {THREECODE_PT, 44, 20, 0},
  2405. X   {THREECODE_PT, 44, 20, 1},
  2406. X   {THREECODE_PT, 44, 20, 2},
  2407. X   {THREECODE_PT, 44, 20, 3},
  2408. X   {THREECODE_PT, 44, 20, 4},
  2409. X   {THREECODE_PT, 44, 20, 5},
  2410. X   {THREECODE_PT, 44, 20, 6},
  2411. X   {THREECODE_PT, 44, 20, 7},
  2412. X   {THREECODE_PT, 44, 20, 8},
  2413. X   {THREECODE_PT, 44, 20, 9},
  2414. X   {THREECODE, 44, 20, 25},
  2415. X   {THREECODE, 44, 20, 24},
  2416. X
  2417. X   {THREECODE, 44, 10, 0},
  2418. X   {THREECODE, 44, 10, 1},
  2419. X   {THREECODE, 44, 10, 2},
  2420. X   {THREECODE, 44, 10, 3},
  2421. X   {THREECODE, 44, 10, 4},
  2422. X   {THREECODE, 44, 10, 5},
  2423. X   {THREECODE, 44, 10, 6},
  2424. X   {THREECODE, 44, 10, 7},
  2425. X   {THREECODE, 44, 10, 8},
  2426. X   {THREECODE, 44, 10, 9},
  2427. X   {THREECODE_PT, 44, 10, 0},
  2428. X   {THREECODE_PT, 44, 10, 1},
  2429. X   {THREECODE_PT, 44, 10, 2},
  2430. X   {THREECODE_PT, 44, 10, 3},
  2431. X   {THREECODE_PT, 44, 10, 4},
  2432. X   {THREECODE_PT, 44, 10, 5},
  2433. X   {THREECODE_PT, 44, 10, 6},
  2434. X   {THREECODE_PT, 44, 10, 7},
  2435. X   {THREECODE_PT, 44, 10, 8},
  2436. X   {THREECODE_PT, 44, 10, 9},
  2437. X   {THREECODE, 44, 10, 25},
  2438. X   {THREECODE, 44, 10, 24},
  2439. X
  2440. X/* RCL */
  2441. X   {TWOCODE_9, 45, 0},
  2442. X   {TWOCODE_9, 45, 1},
  2443. X   {TWOCODE_9, 45, 2},
  2444. X   {TWOCODE_9, 45, 3},
  2445. X   {TWOCODE_9, 45, 4},
  2446. X   {TWOCODE_9, 45, 5},
  2447. X   {TWOCODE_9, 45, 6},
  2448. X   {TWOCODE_9, 45, 7},
  2449. X   {TWOCODE_9, 45, 8},
  2450. X   {TWOCODE_9, 45, 9},
  2451. X   {TWOCODE_PT, 45, 0},
  2452. X   {TWOCODE_PT, 45, 1},
  2453. X   {TWOCODE_PT, 45, 2},
  2454. X   {TWOCODE_PT, 45, 3},
  2455. X   {TWOCODE_PT, 45, 4},
  2456. X   {TWOCODE_PT, 45, 5},
  2457. X   {TWOCODE_PT, 45, 6},
  2458. X   {TWOCODE_PT, 45, 7},
  2459. X   {TWOCODE_PT, 45, 8},
  2460. X   {TWOCODE_PT, 45, 9},
  2461. X   {TWOCODE, 45, 25},
  2462. X   {TWOCODE, 45, 24},
  2463. X};
  2464. SHAR_EOF
  2465. echo "extracting prog_codes.h"
  2466. sed 's/^X//' << \SHAR_EOF > prog_codes.h
  2467. X/* There are 6 different ways in which program lines are displayed. cf io.c */
  2468. X#define ONECODE 0
  2469. X#define TWOCODE 1
  2470. X#define TWOCODE_9 2
  2471. X#define TWOCODE_PT 3
  2472. X#define THREECODE 4
  2473. X#define THREECODE_PT 5
  2474. X
  2475. Xstruct KeyCode {
  2476. X   BYTE Type; /* The display method */
  2477. X   BYTE c1, c2, c3; /* The codes to display */
  2478. X};
  2479. X
  2480. X/* This array is indexed by the instruction code (from codes.h). Therefore, if
  2481. X  that file is changed, the codes must also be changed. */
  2482. Xextern struct KeyCode keycodes[];
  2483. SHAR_EOF
  2484. echo "extracting support.c"
  2485. sed 's/^X//' << \SHAR_EOF > support.c
  2486. X#include "math.h"
  2487. X
  2488. X#include "hp11/support.h"
  2489. X
  2490. Xdouble sign(r)
  2491. Xdouble r;
  2492. X{
  2493. X   if (r < 0.0) return(-1.0);
  2494. X   else if (r == 0.0) return (0.0);
  2495. X   else return(1.0);
  2496. X}
  2497. X
  2498. Xvoid Rect(r, phi, x, y)
  2499. Xdouble r, phi, *x, *y;
  2500. X{
  2501. X   *x = r * cos(phi);
  2502. X   *y = r * sin(phi);
  2503. X}
  2504. X
  2505. Xvoid Polar(x, y, r, phi)
  2506. Xdouble x, y, *r, *phi;
  2507. X{
  2508. X   *r = sqrt(x * x + y * y);
  2509. X   *phi = atan2(y, x);
  2510. X}
  2511. X
  2512. Xdouble stirling(n)
  2513. Xdouble n;
  2514. X{
  2515. X   double y = 1 / (12 * n);
  2516. X
  2517. X   return (pow(n / E, n) * sqrt(2 * PI * n) * (1 + y * (1 + y * (0.5 - y * (4.6333333333333333 + y * 4.7583333333333333)))));
  2518. X}
  2519. X
  2520. Xdouble gamma(x)
  2521. Xdouble x;
  2522. X{
  2523. X   double fx, tx, res, i;
  2524. X
  2525. X   if (x >= 15.0) return(stirling(x - 1));
  2526. X   else {
  2527. X      if ((fx = modf(x, &tx)) < 0) { tx -= 1.0; fx += 1.0; } /* give real int & frac */
  2528. X
  2529. X      if (fx == 0 && tx < 0) return(-HUGE);
  2530. X      if (tx < -200) return(0.0); /* Underflow */
  2531. X
  2532. X      res = stirling(fx + 14.0);
  2533. X      for (i = 14.0; i >= tx; i -= 1.0) res /= i + fx;
  2534. X
  2535. X      return(res);
  2536. X   }
  2537. X}
  2538. X
  2539. Xdouble factorial(x)
  2540. Xint x;
  2541. X{
  2542. X   double r = 1.0;
  2543. X
  2544. X   if (x > 250) r = HUGE; /* Certainly too big */
  2545. X   else for (; x > 0; x--) r *= x;
  2546. X
  2547. X   return(r);
  2548. X}
  2549. X
  2550. Xdouble Perm(x, y)
  2551. Xint x, y;
  2552. X{
  2553. X   double i, res = 1.0, lim = x - y;
  2554. X
  2555. X   for (i = x; i > lim; i -= 1.0) res *= i;
  2556. X
  2557. X   return(res);
  2558. X}
  2559. X
  2560. Xdouble Comb(x, y)
  2561. Xint x,y;
  2562. X{
  2563. X   double i, lim = y, res = Perm(x, y);
  2564. X
  2565. X   for (i = 1; i <= lim; i += 1.0) res /= i;
  2566. X
  2567. X   return(res);
  2568. X}
  2569. X
  2570. Xdouble hr(x)
  2571. Xdouble x;
  2572. X{
  2573. X   double h, m, s;
  2574. X
  2575. X   /* f = modf(x, &i) returns the frcational part of x in f and the integral part in i (all double) */
  2576. X   m = 100.0 * modf(x, &h);
  2577. X   s = 100.0 * modf(m, &m);
  2578. X
  2579. X   return(h + m / 60.0 + s / 3600.0);
  2580. X}
  2581. X
  2582. Xdouble hms(x)
  2583. Xdouble x;
  2584. X{
  2585. X   double h, m, s;
  2586. X
  2587. X   m = 60.0 * modf(x, &h);
  2588. X   s = 60.0 * modf(m, &m);
  2589. X
  2590. X   return(h + m / 100.0 + s / 10000.0);
  2591. X}
  2592. X
  2593. Xdouble trunc(x)
  2594. Xdouble x;
  2595. X{
  2596. X   modf(x, &x);
  2597. X   return(x);
  2598. X}
  2599. X
  2600. Xdouble frac(x)
  2601. Xdouble x;
  2602. X{
  2603. X   return(modf(x, &x));
  2604. X}
  2605. X
  2606. Xdouble asinh(x)
  2607. Xdouble x;
  2608. X{
  2609. X   return(log(x + sqrt(x * x + 1)));
  2610. X}
  2611. X
  2612. Xdouble acosh(x)
  2613. Xdouble x;
  2614. X{
  2615. X   if (x < 1.0) return(0.0);
  2616. X   else return(log(x + sqrt(x * x -1)));
  2617. X}
  2618. X
  2619. Xdouble atanh(x)
  2620. Xdouble x;
  2621. X{
  2622. X   if (x > 1.0) return(0.0);
  2623. X   else return(log((1.0 + x) / (1.0 - x)) / 2.0);
  2624. X}
  2625. SHAR_EOF
  2626. echo "extracting support.h"
  2627. sed 's/^X//' << \SHAR_EOF > support.h
  2628. X/* Support routines for the HP11, but not HP11 specific */
  2629. X
  2630. X/* Macros to convert to/from grad's/degrees from/to radians */
  2631. X#define TDEG(x) (x) * (180.0 / PI)
  2632. X#define FDEG(x) (x) * (PI / 180.0)
  2633. X#define TGRAD(x) (x) * (200.0 / PI)
  2634. X#define FGRAD(x) (x) * (PI / 200.0)
  2635. X#define E 2.718281828
  2636. X
  2637. Xdouble sign(double); /* return the sign of the number */
  2638. Xvoid Rect(double, double, double *, double *); /* Convert from Polar to Rectangular */
  2639. Xvoid Polar(double, double, double *, double *); /* Convert from Rectangular to Polar */
  2640. Xdouble Perm(int, int); /* Compute the permutation of y items taken x at a time (ordered) */
  2641. Xdouble Comb(int, int); /* Compute the combination of y items taken x at a time (unorderd) */
  2642. Xdouble hr(double); /* Convert to decimal hours */
  2643. Xdouble hms(double); /* Convert from decimal hours to hh.mmss */
  2644. Xdouble trunc(double); /* Truncate double, returning a double */
  2645. Xdouble frac(double); /* Take the fractional part of a double */
  2646. Xdouble factorial(int); /* Compute the factorial */
  2647. Xdouble gamma(double); /* Compute the gamma function */
  2648. Xdouble stirling(double); /* Stirling's approximation */
  2649. X/* Hyperbolic reciprocal functions (the others are in the library) */
  2650. Xdouble asinh(double), acosh(double), atanh(double);
  2651. SHAR_EOF
  2652. echo "End of archive 3 (of 3)"
  2653. # if you want to concatenate archives, remove anything after this line
  2654. exit
  2655.